function EntityStorageBase::setStaticCache

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Entity/EntityStorageBase.php \Drupal\Core\Entity\EntityStorageBase::setStaticCache()
  2. 10 core/lib/Drupal/Core/Entity/EntityStorageBase.php \Drupal\Core\Entity\EntityStorageBase::setStaticCache()
  3. 9 core/lib/Drupal/Core/Entity/EntityStorageBase.php \Drupal\Core\Entity\EntityStorageBase::setStaticCache()
  4. 8.9.x core/lib/Drupal/Core/Entity/EntityStorageBase.php \Drupal\Core\Entity\EntityStorageBase::setStaticCache()

Stores entities in the static entity cache.

Parameters

\Drupal\Core\Entity\EntityInterface[] $entities: Entities to store in the cache.

2 calls to EntityStorageBase::setStaticCache()
ContentEntityStorageBase::setStaticCache in core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php
Stores entities in the static entity and entity revision cache.
EntityStorageBase::loadMultiple in core/lib/Drupal/Core/Entity/EntityStorageBase.php
Loads one or more entities.
1 method overrides EntityStorageBase::setStaticCache()
ContentEntityStorageBase::setStaticCache in core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php
Stores entities in the static entity and entity revision cache.

File

core/lib/Drupal/Core/Entity/EntityStorageBase.php, line 209

Class

EntityStorageBase
A base entity storage class.

Namespace

Drupal\Core\Entity

Code

protected function setStaticCache(array $entities) {
  $has_uuid = $this->entityType
    ->hasKey('uuid');
  if ($this->entityType
    ->isStaticallyCacheable()) {
    foreach ($entities as $entity) {
      $this->memoryCache
        ->set($this->buildCacheId($entity->id()), $entity, MemoryCacheInterface::CACHE_PERMANENT, [
        $this->memoryCacheTag,
      ]);
      if ($has_uuid) {
        // Pre-cache the UUID of this entity to speed up ::loadEntityByUuid
        // @see ::loadByProperties
        $this->memoryCache
          ->set(\sprintf('uuid_lookup:%s:%s', $this->entityTypeId, $entity->uuid()), [
          $entity->id(),
        ], MemoryCacheInterface::CACHE_PERMANENT, [
          $this->uuidMemoryCacheTag,
        ]);
      }
    }
  }
}

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