You are here

public function ChainedStorageExpirable::getMultiple in Supercache 8

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

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

@todo What's returned for non-existing keys?

Parameters

array $keys: A list of keys to retrieve.

Return value

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

Overrides DatabaseStorageExpirable::getMultiple

File

src/KeyValueStore/ChainedStorageExpirable.php, line 91
Contains \Drupal\supercache\KeyValueStore\ChainedStorageExpirable.

Class

ChainedStorageExpirable
Defines a default key/value store implementation for expiring items.

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)) {

      // In order to populate the cache we need to know what the
      // expiration times for each of these key value pairs are,
      // and the DatabaseStorageExpirable implementation does
      // not provide this.
      $this->cache
        ->setMultiple($this
        ->KeyValueToCache($persisted, $this
        ->getExpirations(array_keys($persisted))));
    }
    $this
      ->populateMissingValuesLocal($keys, $persisted);
  }
  $result = $cached + $persisted;
  return $result;
}