You are here

public function ChainedFastRawBackend::getMultiple in Supercache 2.0.x

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

Returns data from the persistent cache when given an array of cache IDs.

Parameters

array $cids: An array of cache IDs for the data to retrieve. This is passed by reference, and will have the IDs successfully returned from cache removed.

Return value

array An array of cache item objects indexed by cache ID.

Overrides CacheRawBackendInterface::getMultiple

See also

\Drupal\Core\Cache\CacheRawBackendInterface::get()

1 call to ChainedFastRawBackend::getMultiple()
ChainedFastRawBackend::get in src/Cache/ChainedFastRawBackend.php
Returns data from the persistent cache.

File

src/Cache/ChainedFastRawBackend.php, line 129
Contains \Drupal\supercache\Cache\ChainedFastRawBackend.

Class

ChainedFastRawBackend
Defines a backend with a fast and a consistent backend chain.

Namespace

Drupal\supercache\Cache

Code

public function getMultiple(&$cids) {
  $this
    ->clearFastStorageIfInvalid();
  $cids_copy = $cids;
  $cache = array();
  try {
    $items = $this->fastBackend
      ->getMultiple($cids);
  } catch (\Exception $e) {
    $cids = $cids_copy;
    $items = array();
  }

  // Even if items were successfully fetched from the fast backend, they
  // are potentially invalid if older than the last time the bin was
  // written to in the consistent backend, so only keep ones that aren't.
  $cache = $items;

  // If there were any cache entries that were not available in the fast
  // backend, retrieve them from the consistent backend and store them in the
  // fast one.
  if ($cids) {
    $missing = array();
    $cached = $this->consistentBackend
      ->getMultiple($cids);
    foreach ($cached as $cid => $item) {
      $cache[$cid] = $item;
      $missing[$cid] = [
        'data' => $item->data,
      ];
    }
    if (!empty($missing)) {

      // TODO: Expiration data from the consistent
      // backend is lost here. We are setting items
      // in the fast backend with permanent status...
      // But time based expirations are becoming less
      // relevant, and considering that the items
      // in the consistent backend will actually expire
      // properly, this might not be that of an issue.
      $this->fastBackend
        ->setMultiple($missing);
    }
  }
  return $cache;
}