You are here

public function ChainedFastRawBackend::counterGetMultiple in Supercache 8

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

Get multiple counter values at once.

Parameters

array $cids: An array of cache id's to retrieve.

Overrides CacheRawBackendInterface::counterGetMultiple

See also

self::getCounter()

File

src/Cache/ChainedFastRawBackend.php, line 295
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 counterGetMultiple(array &$cids) {
  $this
    ->clearFastStorageIfInvalid();
  $cids_copy = $cids;
  $cache = array();
  try {
    $items = $this->fastBackend
      ->counterGetMultiple($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
      ->counterGetMultiple($cids);
    foreach ($cached as $cid => $item) {
      $cache[$cid] = $item;
      $missing[$cid] = $item;
    }
    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.
      // A possibility is not to support expiration
      // for the ChainedFastRawBackend...
      $this->fastBackend
        ->counterSetMultiple($missing);
    }
  }
  return $cache;
}