public DatabaseBackend::getMultiple(&$cids, $allow_invalid = FALSE)
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
See also
\Drupal\Core\Cache\CacheBackendInterface::get()
File
- core/lib/Drupal/Core/Cache/DatabaseBackend.php, line 70
Class
- DatabaseBackend
- Defines a default cache implementation.
Namespace
Drupal\Core\Cache
Code
public function getMultiple(&$cids, $allow_invalid = FALSE) { $cid_mapping = array(); foreach ($cids as $cid) { $cid_mapping[$this->normalizeCid($cid)] = $cid; } // When serving cached pages, the overhead of using ::select() was found // to add around 30% overhead to the request. Since $this->bin is a // variable, this means the call to ::query() here uses a concatenated // string. This is highly discouraged under any other circumstances, and // is used here only due to the performance overhead we would incur // otherwise. When serving an uncached page, the overhead of using // ::select() is a much smaller proportion of the request. $result = array(); try { $result = $this->connection->query('SELECT cid, data, created, expire, serialized, tags, checksum FROM {' . $this->connection->escapeTable($this->bin) . '} WHERE cid IN ( :cids[] ) ORDER BY cid', array(':cids[]' => array_keys($cid_mapping))); } catch (\Exception $e) { // Nothing to do. } $cache = array(); foreach ($result as $item) { // Map the cache ID back to the original. $item->cid = $cid_mapping[$item->cid]; $item = $this->prepareItem($item, $allow_invalid); if ($item) { $cache[$item->cid] = $item; } } $cids = array_diff($cids, array_keys($cache)); return $cache; }
Please login to continue.