Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DatabaseBackend.php

function DatabaseBackend::getMultiple

Overrides CacheBackendInterface::getMultiple

1 call to DatabaseBackend::getMultiple()
DatabaseBackend::get in core/lib/Drupal/Core/Cache/DatabaseBackend.php
Returns data from the persistent cache.

File

core/lib/Drupal/Core/Cache/DatabaseBackend.php, line 117

Class

DatabaseBackend
Defines a default cache implementation.

Namespace

Drupal\Core\Cache

Code

public function getMultiple(&$cids, $allow_invalid = FALSE) {
    $cid_mapping = [];
    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 = [];
    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]', [
            ':cids[]' => array_keys($cid_mapping),
        ]);
    } catch (\Exception) {
        // Nothing to do.
    }
    $cache = [];
    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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal