You are here

function MemcacheStorage::clear in Memcache Storage 7

Implements DrupalCacheInterface::clear().

Overrides DrupalCacheInterface::clear

1 call to MemcacheStorage::clear()
MemcacheStoragePageCache::clear in ./memcache_storage.page_cache.inc
Implements DrupalCacheInterface::clear().
1 method overrides MemcacheStorage::clear()
MemcacheStoragePageCache::clear in ./memcache_storage.page_cache.inc
Implements DrupalCacheInterface::clear().

File

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

Class

MemcacheStorage
Class handles memcached cache objects.

Code

function clear($cid = NULL, $wildcard = FALSE) {

  // Function like cache_clear_all(NULL, 'cache_bin');
  // We should invalidate all old cache.
  if (empty($cid)) {
    $cache_min_lifetime = variable_get('cache_lifetime', 0);
    if (!empty($cache_min_lifetime)) {

      // Load timestamp of last cache flush for this bin.
      $cache_last_flush = variable_get('cache_flush_' . $this->bin, 0);
      if (empty($cache_last_flush) || REQUEST_TIME > $cache_last_flush + $cache_min_lifetime) {

        // Set timestamp when cache bin was flushed.
        // Actually, before cache load we will check this variable.
        variable_set('cache_flush_' . $this->bin, REQUEST_TIME);
      }
    }
    else {

      // No minimum cache lifetime, flush all temporary cache entries now.
      variable_set('cache_flush_' . $this->bin, REQUEST_TIME);
    }
  }
  else {
    if ($wildcard) {
      if ($cid == '*') {

        // Simple changing index for bin storage will flushes the whole cache
        // bin, because it is used for building memcache key.
        $this
          ->increaseBinIndex();
      }
      else {

        // In case of wildcard invalidation just store info about wildcard
        // in the memcached. Later we will use bulk invalidation to delete
        // invalid cache from memcached. See memcache_storage_wildcard_flush()
        // for detailed overview.
        $this->wildcards[$cid] = REQUEST_TIME;
        MemcacheStorageAPI::set('memcache_storage_wildcards', $this->wildcards, CACHE_PERMANENT, $this
          ->cacheBinName());
      }
    }
    elseif (is_array($cid)) {

      // Remove the current cache ID from the list of cache IDs in use.
      $this
        ->removeCacheIDs($cid);

      // Delete cache from memcached instance.
      MemcacheStorageAPI::deleteMultiple($cid, $this
        ->cacheBinName());
    }
    else {

      // Remove the current cache ID from the list of cache IDs in use.
      $this
        ->removeCacheID($cid);

      // Just delete cache from memcached instance.
      MemcacheStorageAPI::delete($cid, $this
        ->cacheBinName());
    }
  }
  return TRUE;
}