You are here

function DrupalFileCache::clear in File Cache 7

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

Parameters

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

$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 bin $bin will be emptied.

Overrides DrupalCacheInterface::clear

File

./filecache.inc, line 391
DrupalFileCache class that implements DrupalCacheInterface.

Class

DrupalFileCache

Code

function clear($cid = NULL, $wildcard = FALSE) {
  global $user;
  if (!$this->ok) {
    return;
  }

  // parts are shamelessy copied from includes/cache.inc
  if (empty($cid)) {
    if (variable_get('cache_lifetime', 0)) {

      // We store the time in the current user's $user->cache variable which
      // will be saved into the sessions bin by _drupal_session_write(). We then
      // simulate that the cache was flushed for this user by not returning
      // cached data that was cached before the timestamp.
      $user->cache = REQUEST_TIME;
      $cache_flush = variable_get('cache_flush_' . $this->bin, 0);
      if ($cache_flush == 0) {

        // This is the first request to clear the cache, start a timer.
        variable_set('cache_flush_' . $this->bin, REQUEST_TIME);
      }
      elseif (REQUEST_TIME > $cache_flush + variable_get('cache_lifetime', 0)) {

        // Clear the cache for everyone, cache_lifetime seconds have
        // passed since the first request to clear the cache.
        $this
          ->delete_expired();
        variable_set('cache_flush_' . $this->bin, 0);
      }
    }
    else {

      // No minimum cache lifetime, flush all temporary cache entries now.
      $this
        ->delete_expired();
    }
  }
  else {
    if ($wildcard) {
      if ($cid == '*') {
        $this
          ->delete_wildcard('');
      }
      else {
        $this
          ->delete_wildcard($cid);
      }
    }
    elseif (is_array($cid)) {
      foreach ($cid as $one_cid) {
        $this
          ->delete_one($one_cid);
      }
    }
    else {
      $this
        ->delete_one($cid);
    }
  }
}