You are here

public function ChainedStorage::getMultiple in Supercache 2.0.x

Same name and namespace in other branches
  1. 8 src/KeyValueStore/ChainedStorage.php \Drupal\supercache\KeyValueStore\ChainedStorage::getMultiple()

Returns the stored key/value pairs for a given set of keys.

@todo Determine the best return value for non-existing keys in https://www.drupal.org/node/2787737

Parameters

array $keys: A list of keys to retrieve.

Return value

array An associative array of items successfully returned, indexed by key.

Overrides DatabaseStorage::getMultiple

File

src/KeyValueStore/ChainedStorage.php, line 77
Contains \Drupal\supercache\KeyValueStore\ChainedStorage;

Class

ChainedStorage
Defines a chained key value storage that uses any cache backend on top of the database default key/value storage.

Namespace

Drupal\supercache\KeyValueStore

Code

public function getMultiple(array $keys) {
  $cached = [];
  if ($cache = $this->cache
    ->getMultiple($keys)) {
    $cached = $this
      ->CacheToKeyValue($cache);
  }
  $persisted = [];
  if (!empty($keys)) {
    $persisted = parent::getMultiple($keys);
    if (!empty($persisted)) {
      $this->cache
        ->setMultiple($this
        ->KeyValueToCache($persisted));
    }
    $this
      ->populateMissingValuesLocal($keys, $persisted);
  }
  $result = array_merge($cached, $persisted);
  return $result;
}