You are here

public function Redis_Cache::clear in Redis 7.3

Same name and namespace in other branches
  1. 7.2 lib/Redis/Cache.php \Redis_Cache::clear()

Expires 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 or an array of cache IDs. Otherwise, all cache entries that can expire are deleted. The $wildcard argument will be ignored if set to NULL.

$wildcard: If TRUE, the $cid argument must contain a string value and cache IDs starting with $cid are deleted in addition to the exact cache ID specified by $cid. If $wildcard is TRUE and $cid is '*', the entire cache is emptied.

Overrides DrupalCacheInterface::clear

File

lib/Redis/Cache.php, line 505

Class

Redis_Cache
Because those objects will be spawned during boostrap all its configuration must be set in the settings.php file.

Code

public function clear($cid = null, $wildcard = false) {
  if (null === $cid && !$wildcard) {

    // Drupal asked for volatile entries flush, this will happen
    // during cron run, mostly
    $this
      ->setLastFlushTime(false, true);
    if (!$this->isSharded && $this->allowTemporaryFlush) {
      $this->backend
        ->flushVolatile();
    }
  }
  else {
    if ($wildcard) {
      if (empty($cid)) {

        // This seems to be an error, just do nothing.
        return;
      }
      if ('*' === $cid) {

        // Use max() to ensure we invalidate both correctly
        $this
          ->setLastFlushTime(true);
        if (!$this->isSharded) {
          $this->backend
            ->flush();
        }
      }
      else {
        if (!$this->isSharded) {
          $this->backend
            ->deleteByPrefix($cid);
        }
        else {

          // @todo This needs a map algorithm the same way memcache
          // module implemented it for invalidity by prefixes. This
          // is a very stupid fallback
          $this
            ->setLastFlushTime(true);
        }
      }
    }
    else {
      if (is_array($cid)) {
        $this->backend
          ->deleteMultiple($cid);
      }
      else {
        $this->backend
          ->delete($cid);
      }
    }
  }
}