You are here

function Redis_Cache_PhpRedis::clear in Redis 7

Same name and namespace in other branches
  1. 7.2 lib/Redis/Cache/PhpRedis.php \Redis_Cache_PhpRedis::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/PhpRedis.php, line 118

Class

Redis_Cache_PhpRedis
Predis cache backend.

Code

function clear($cid = NULL, $wildcard = FALSE) {
  $client = Redis_Client::getClient();
  $many = FALSE;

  // Redis handles for us cache key expiration.
  if (!isset($cid)) {
    return;
  }
  if ('*' !== $cid && $wildcard) {
    $key = $this
      ->_buildKey('*' . $cid . '*');
    $many = TRUE;
  }
  else {
    if ('*' === $cid) {
      $key = $this
        ->_buildKey($cid);
      $many = TRUE;
    }
    else {
      $key = $this
        ->_buildKey($cid);
    }
  }
  if ($many) {
    $keys = $client
      ->keys($key);

    // Attempt to clear an empty array will raise exceptions.
    if (!empty($keys)) {
      $client
        ->del($keys);
    }
  }
  else {
    $client
      ->del(array(
      $key . ':data',
      $key . ':serialized',
    ));
  }
}