protected function ContentEntityStorageBase::getFromPersistentCache

protected ContentEntityStorageBase::getFromPersistentCache(array &$ids = NULL)

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.

File

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

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 array();
  }
  $entities = array();
  // Build the list of cache entries to retrieve.
  $cid_map = array();
  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;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!ContentEntityStorageBase.php/function/ContentEntityStorageBase::getFromPersistentCache/8.1.x