You are here

public static function MemcacheStorageAPI::deleteMultiple in Memcache Storage 7

Delete multiple cache items from memcached pool. Provide debug logging.

1 call to MemcacheStorageAPI::deleteMultiple()
MemcacheStorage::clear in ./memcache_storage.inc
Implements DrupalCacheInterface::clear().

File

./memcache_storage.api.inc, line 420
Provide class that processes memcached operations.

Class

MemcacheStorageAPI
Integrates with memcache API.

Code

public static function deleteMultiple($cache_ids, $cache_bin = '') {

  // Get memcache object.
  $memcache = self::openConnection($cache_bin);

  // No memcache connection.
  if (empty($memcache)) {
    return FALSE;
  }

  // If current instance is Memcache which doesn't support deleteMulti
  // requests, then just execute delete commands one after another.
  if ($memcache instanceof Memcache) {
    foreach ($cache_ids as $cache_id) {
      self::delete($cache_id, $cache_bin);
    }
    return TRUE;
  }

  // Build unique cache ids.
  $cids = array();
  foreach ($cache_ids as $cache_id) {
    $safe_key = self::preprocessCacheKey($cache_id, $cache_bin);
    $cids[$safe_key] = $cache_id;
  }

  // Run initial debug actions.
  if (variable_get('memcache_storage_debug', FALSE)) {
    self::initialDebugActions();
  }
  $result = @$memcache
    ->deleteMulti(array_keys($cids));

  // Return cache with correct keys.
  $output = array();
  if (!empty($result)) {
    $cache_keys = array_keys($result);
    foreach ($cache_keys as $cache_key) {
      $output[$cids[$cache_key]] = $result[$cache_key];
    }
  }

  // Run final debug actions.
  if (variable_get('memcache_storage_debug', FALSE)) {
    self::finalDebugActions('delete', $cache_bin, array_values($cids), $cids, $output);
  }
  return $output;
}