You are here

function ad_cache_memcache_get_ids in Advertisement 5.2

Same name and namespace in other branches
  1. 5 cache/memcache/ad_cache_memcache.inc \ad_cache_memcache_get_ids()
  2. 6 cache/memcache/ad_cache_memcache.inc \ad_cache_memcache_get_ids()
1 call to ad_cache_memcache_get_ids()
ad_cache_memcache in cache/memcache/ad_cache_memcache.inc
Called by adserve.inc, display an ad from memcache.

File

cache/memcache/ad_cache_memcache.inc, line 130

Code

function ad_cache_memcache_get_ids($op = 'default', $id = 0) {
  switch ($op) {
    case 'node':
      $ids = explode(',', $id);
      break;
    case 'taxonomy':
      $ids = ad_memcache_get("ad-taxonomy-cache-{$id}");
      if (!$ids || empty($ids)) {
        $taxonomy = ad_memcache_get('ad-taxonomy');
        $cache = array();
        $ids = explode(',', $id);
        foreach ($ids as $tid) {
          if (is_array($taxonomy[$tid])) {
            $cache += $taxonomy[$tid];
          }
        }

        // Rebuild keys from 0, cache for quick re-use on next ad display.
        $ids = array_values($cache);
        ad_memcache_set("ad-taxonomy-cache-{$id}", $ids);
      }
      break;
    default:
      $taxonomy = ad_memcache_get('ad-taxonomy');
      $ids = $taxonomy[0];
      break;
  }
  return $ids;
}