You are here

public function CacheBackendMongodb::getMultiple in MongoDB 8

Implements Drupal\Core\Cache\CacheBackendInterface::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.

bool $allow_invalid: (optional) If TRUE, cache items may be returned even if they have expired or been invalidated. Such items may sometimes be preferred, if the alternative is recalculating the value stored in the cache, especially if another concurrent thread is already recalculating the same value. The "valid" property of the returned objects indicates whether the items are valid or not. Defaults to FALSE.

Return value

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

Overrides CacheBackendInterface::getMultiple

1 call to CacheBackendMongodb::getMultiple()
CacheBackendMongodb::get in src/CacheBackendMongodb.php
Implements Drupal\Core\Cache\CacheBackendInterface::get().

File

src/CacheBackendMongodb.php, line 92
Definition of Drupal\mongodb/CacheBackendMongodb.

Class

CacheBackendMongodb
Defines MongoDB cache implementation.

Namespace

Drupal\mongodb

Code

public function getMultiple(&$cids, $allow_invalid = FALSE) {
  $find = array();
  $find['_id']['$in'] = array_map('strval', $cids);
  $result = $this->collection
    ->find($find);
  $cache = array();
  foreach ($result as $item) {
    $item = $this
      ->prepareItem((object) $item, $allow_invalid);
    if ($item) {
      $cache[$item->cid] = $item;
    }
  }
  $cids = array_diff($cids, array_keys($cache));
  return $cache;
}