function ContentEntityStorageBase::getFromPersistentCache

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::getFromPersistentCache()
  2. 10 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::getFromPersistentCache()
  3. 11.x core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::getFromPersistentCache()

Gets entities from the persistent cache backend.

Parameters

array|null &$ids: If not empty, return entities that match these IDs. IDs that were found will be removed from the list.

Return value

\Drupal\Core\Entity\ContentEntityInterface[] Array of entities from the persistent cache.

2 calls to ContentEntityStorageBase::getFromPersistentCache()
ContentEntityStorageBase::loadUnchanged in core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php
Loads an unchanged entity from the database.
SqlContentEntityStorage::doLoadMultiple in core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
Performs storage-specific loading of entities.

File

core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php, line 1017

Class

ContentEntityStorageBase
Base class for content entity storage handlers.

Namespace

Drupal\Core\Entity

Code

protected function getFromPersistentCache(array &$ids = NULL) {
    if (!$this->entityType
        ->isPersistentlyCacheable() || empty($ids)) {
        return [];
    }
    $entities = [];
    // Build the list of cache entries to retrieve.
    $cid_map = [];
    foreach ($ids as $id) {
        $cid_map[$id] = $this->buildCacheId($id);
    }
    $cids = array_values($cid_map);
    if ($cache = $this->cacheBackend
        ->getMultiple($cids)) {
        // Get the entities that were found in the cache.
        foreach ($ids as $index => $id) {
            $cid = $cid_map[$id];
            if (isset($cache[$cid])) {
                $entities[$id] = $cache[$cid]->data;
                unset($ids[$index]);
            }
        }
    }
    return $entities;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.