You are here

function cache_clear_all in Memcache API and Integration 6

Same name in this branch
  1. 6 memcache.db.inc \cache_clear_all()
  2. 6 memcache.inc \cache_clear_all()
Same name and namespace in other branches
  1. 5.2 memcache.db.inc \cache_clear_all()
  2. 5.2 memcache.inc \cache_clear_all()
  3. 5 memcache.db.inc \cache_clear_all()
  4. 5 memcache.inc \cache_clear_all()

Expire data from the cache. If called without arguments, expirable entries will be cleared from the cache_page and cache_block tables.

Parameters

$cid: If set, the cache ID to delete. Otherwise, all cache entries that can expire are deleted.

$table: If set, the table $table to delete from. Mandatory argument if $cid is set.

$wildcard: If set to TRUE, the $cid is treated as a substring to match rather than a complete ID. The match is a right hand match. If '*' is given as $cid, the table $table will be emptied.

7 calls to cache_clear_all()
filter_user in ./memcache-session.inc
Implement hook_user() using a required module's namespace since memcache is not a module and thus can't implement hooks directly.
MemCacheClearCase::clearCidTest in tests/memcache.test
Test clearing using a cid.
MemCacheClearCase::clearWildcardPrefixTest in tests/memcache.test
Test cache clears using wildcard prefixes.
MemCacheClearCase::testClearCacheLifetime in tests/memcache.test
Test full bin flushes with cache lifetime.
MemCacheClearCase::testClearWildcardFull in tests/memcache.test
Test full bin flushes with no cache lifetime.

... See full list

File

./memcache.inc, line 258

Code

function cache_clear_all($cid = NULL, $table = NULL, $wildcard = FALSE) {

  // Handle database fallback first.
  $bins = variable_get('memcache_bins', array());
  if (!is_null($table) && isset($bins[$table]) && $bins[$table] == 'database') {
    return _cache_clear_all($cid, $table, $wildcard);
  }
  if (dmemcache_object($table) === FALSE) {

    // No memcache connection.
    return;
  }
  if (!isset($cid) && isset($table)) {

    // cache_clear_all(NULL, $table) is for garbage collection only, memcache
    // does not need this due to design, so make these calls a no-op.
    return;
  }
  elseif (!isset($cid) && !isset($table)) {
    cache_clear_all(MEMCACHE_CONTENT_FLUSH, 'cache_block');
    cache_clear_all(MEMCACHE_CONTENT_FLUSH, 'cache_page');
    return;
  }
  elseif (($cid == '*' || $cid == '') && $wildcard) {

    // Since memcache works with a single memcache bin, full wildcard flushes
    // are tracked in a variable rather than flushing the bin.
    memcache_variable_set("cache_flush_{$table}", time());
  }
  elseif ($cid == MEMCACHE_CONTENT_FLUSH) {

    // Update the timestamp of the last global flushing of this table.  When
    // retrieving data from this table, we will compare the cache creation
    // time minus the cache_flush time to the cache_lifetime to determine
    // whether or not the cached item is still valid.
    memcache_variable_set("cache_content_flush_{$table}", time());
    if (variable_get('cache_lifetime', 0)) {

      // We store the time in the current user's session which is saved into
      // the sessions table by sess_write().  We then simulate that the cache
      // was flushed for this user by not returning cached data to this user
      // that was cached before the timestamp.
      if (isset($_SESSION['cache_flush'])) {
        $cache_tables = $_SESSION['cache_flush'];
      }
      else {
        $cache_tables = array();
      }

      // Use time() rather than request time here for correctness.
      $cache_tables[$table] = time();
      $_SESSION['cache_flush'] = $cache_tables;
    }
  }
  elseif ($wildcard) {

    // Register a wildcard flush for current cid
    memcache_wildcards($cid, $table, TRUE);
  }
  else {
    dmemcache_delete($cid, $table);
  }
}