You are here

protected function Redis_Cache_Predis::clearWithoutEval in Redis 7.2

1 call to Redis_Cache_Predis::clearWithoutEval()
Redis_Cache_Predis::clear in lib/Redis/Cache/Predis.php
Expires data from the cache.

File

lib/Redis/Cache/Predis.php, line 167

Class

Redis_Cache_Predis
Predis cache backend.

Code

protected function clearWithoutEval($cid = NULL, $wildcard = FALSE) {
  $keys = array();
  $skey = $this
    ->getKey(Redis_Cache_Base::TEMP_SET);
  $client = Redis_Client::getClient();
  if (NULL === $cid) {
    switch ($this
      ->getClearMode()) {

      // One and only case of early return.
      case Redis_Cache_Base::FLUSH_NOTHING:
        return;

      // Default behavior.
      case Redis_Cache_Base::FLUSH_TEMPORARY:
        if (Redis_Cache_Base::LIFETIME_INFINITE == variable_get('cache_lifetime', Redis_Cache_Base::LIFETIME_DEFAULT)) {
          $keys[] = $skey;
          foreach ($client
            ->smembers($skey) as $tcid) {
            $keys[] = $this
              ->getKey($tcid);
          }
        }
        break;

      // Fallback on most secure mode: flush full bin.
      default:
      case Redis_Cache_Base::FLUSH_ALL:
        $keys[] = $skey;
        $cid = '*';
        $wildcard = true;
        break;
    }
  }
  if ('*' !== $cid && $wildcard) {

    // Prefix flush.
    $keys = array_merge($keys, $client
      ->keys($this
      ->getKey($cid . '*')));
  }
  else {
    if ('*' === $cid) {

      // Full bin flush.
      $keys = array_merge($keys, $client
        ->keys($this
        ->getKey('*')));
    }
    else {
      if (empty($keys) && !empty($cid)) {

        // Single key drop.
        $keys[] = $key = $this
          ->getKey($cid);
        $client
          ->srem($skey, $key);
      }
    }
  }
  if (!empty($keys)) {
    if (count($keys) < Redis_Cache_Base::KEY_THRESHOLD) {
      $client
        ->del($keys);
    }
    else {
      $client
        ->pipeline(function ($pipe) use ($keys) {
        do {
          $buffer = array_splice($keys, 0, Redis_Cache_Base::KEY_THRESHOLD);
          $pipe
            ->del($buffer);
        } while (!empty($keys));
      });
    }
  }
}