You are here

function MemcacheStorage::set in Memcache Storage 7

Implements DrupalCacheInterface::set().

Overrides DrupalCacheInterface::set

1 call to MemcacheStorage::set()
MemcacheStoragePageCache::set in ./memcache_storage.page_cache.inc
Ovirrides MemcacheStorage::set().
1 method overrides MemcacheStorage::set()
MemcacheStoragePageCache::set in ./memcache_storage.page_cache.inc
Ovirrides MemcacheStorage::set().

File

./memcache_storage.inc, line 94
Provides class for memcached data handling.

Class

MemcacheStorage
Class handles memcached cache objects.

Code

function set($cid, $data, $expire = CACHE_PERMANENT) {

  // Build cache object (as Drupal always does).
  $cache = new stdClass();
  $cache->cid = $cid;
  $cache->data = $data;
  $cache->created = REQUEST_TIME;
  $cache->expire = $expire;

  // We should always keep in storage temporary cache data.
  // Such cached data invalidates during cache_get() operations.
  if ($expire == CACHE_TEMPORARY) {

    // We should set expiration to 0 for temporary cache.
    // This type of cache could be expired after fetching from memcached storage.
    // @see MemcacheStorage::validateItem().
    $expire = 0;

    // Process custom cache expiration for pages.
    if ($this->bin == 'cache_page') {

      // Developers may set custom expiration for cached pages in settings.php.
      $custom_expiration = variable_get('memcache_storage_page_cache_custom_expiration', FALSE);
      if ($custom_expiration) {
        $expire = variable_get('memcache_storage_page_cache_expire', 0);
      }
    }
  }
  elseif ($expire > REQUEST_TIME) {
    $expire -= REQUEST_TIME;
  }

  // Log info about used cache ID.
  $this
    ->addCacheId($cid, $cache->created);

  // Save data into memcached pool.
  return MemcacheStorageAPI::set($cid, $cache, $expire, $this
    ->cacheBinName());
}