You are here

public function DrupalMemcache::getMulti in Memcache Storage 8

Get the multiple cache items from the memcached pool.

Parameters

array $keys: List of cache keys to receive.

string $cache_bin: Name of the cache bin.

Return value

array List of cached data with cache keys as array keys.

Overrides DrupalMemcachedInterface::getMulti

File

src/DrupalMemcache.php, line 133

Class

DrupalMemcache
Class DrupalMemcache

Namespace

Drupal\memcache_storage

Code

public function getMulti(array $keys, $cache_bin = '') {

  // No point in performing any action is we're not connected to memcached.
  if (empty($this->isConnected)) {
    return [];
  }

  // Format every cache key before the request to memcached pool.
  $memcached_keys = [];
  foreach ($keys as $key) {
    $memcached_key = $this
      ->itemKey($key, $cache_bin);
    $memcached_keys[$memcached_key] = $key;
  }

  // Perform preparations for the debug logging.
  if (!empty($this->debug)) {
    DrupalMemcachedDebug::prepare();
  }

  // Get all cache items from memcached.
  $compression = !empty($this->compressionEnabled) ? MEMCACHE_COMPRESSED : 0;
  $result = $this->memcached
    ->get(array_keys($memcached_keys), $compression);

  // Logs the debug entry about the memcached operation.
  if (!empty($this->debug)) {
    DrupalMemcachedDebug::process('get', $result, $memcached_keys, $cache_bin, $this->cluster);
  }

  // Replace formatted memcached keys by Drupal keys.
  $cache = [];
  foreach ($result as $memcached_key => $value) {
    $normal_key = $memcached_keys[$memcached_key];
    $cache[$normal_key] = $value;
  }
  return $cache;
}