You are here

public function D8Cache::getMultiple in Drupal 8 Cache Backport 7

2 calls to D8Cache::getMultiple()
D8Cache::get in ./d8cache.cache.inc
D8CacheAttachmentsCollector::getMultiple in ./d8cache-ac.cache.inc
1 method overrides D8Cache::getMultiple()
D8CacheAttachmentsCollector::getMultiple in ./d8cache-ac.cache.inc

File

./d8cache.cache.inc, line 80

Class

D8Cache
Defines a Drupal 8 cacheable metadata aware cache backend.

Code

public function getMultiple(&$cids, $allow_invalid = FALSE) {
  $cache = array();
  $cids_map = array_flip($cids);
  foreach ($this->backend
    ->getMultiple($cids) as $cid => $item) {

    // This should never happen.
    if (!isset($cids_map[$cid])) {
      continue;
    }
    $data = $item->data;
    $expire = isset($data->d8cache_expire) ? $data->d8cache_expire : $item->expire;

    // Check expire time.
    $item->valid = $expire === CACHE_PERMANENT || $expire === CACHE_TEMPORARY || $expire >= REQUEST_TIME;

    // Is this packed data?
    if ($data instanceof stdClass && isset($data->d8cache_tags)) {

      // Check if the cache tags are valid.
      if (!$this
        ->checksumValid($data->d8cache_checksum, $data->d8cache_tags)) {
        $item->valid = FALSE;
      }
      $item->data = $data->d8cache_data;
    }
    if (!$allow_invalid && !$item->valid) {
      continue;
    }
    $cache[$cid] = $item;
    unset($cids_map[$cid]);
  }

  // Re-calculate the cids property.
  $cids = array_keys($cids_map);
  return $cache;
}