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 583

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;
}
doc_Drupal
2016-10-29 08:57:33
Comments
Leave a Comment

Please login to continue.