You are here

public function DatabaseRawBackend::getMultiple in Supercache 2.0.x

Same name and namespace in other branches
  1. 8 src/Cache/DatabaseRawBackend.php \Drupal\supercache\Cache\DatabaseRawBackend::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()

2 calls to DatabaseRawBackend::getMultiple()
DatabaseRawBackend::counterGetMultiple in src/Cache/DatabaseRawBackend.php
Get multiple counter values at once.
DatabaseRawBackend::get in src/Cache/DatabaseRawBackend.php
Returns data from the persistent cache.

File

src/Cache/DatabaseRawBackend.php, line 69
Contains \Drupal\supercache\Cache\DatabaseRawBackend.

Class

DatabaseRawBackend
Defines a default cache implementation.

Namespace

Drupal\supercache\Cache

Code

public function getMultiple(&$cids) {
  $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_serialized, data_string, data_int, data_float, expire, storage FROM {' . $this->connection
      ->escapeTable($this->bin) . '} WHERE cid IN ( :cids[] ) AND (expire > :expire OR expire = :expire_permanent) ORDER BY cid', array(
      ':cids[]' => array_keys($cid_mapping),
      ':expire' => (int) $this->requestTime,
      ':expire_permanent' => (int) CacheRawBackendInterface::CACHE_PERMANENT,
    ));
  } 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);
    if ($item) {
      $cache[$item->cid] = $item;
    }
  }
  $cids = array_diff($cids, array_keys($cache));
  return $cache;
}