function ContentEntityStorageBase::resetCache

Resets the entity cache.

Content entities have both an in-memory static cache and a persistent cache. Use this method to clear all caches. To clear just the in-memory cache, use the 'entity.memory_cache' service.

Parameters

array $ids: (optional) If specified, the cache is reset for the entities with the given ids only.

Overrides EntityStorageBase::resetCache

4 calls to ContentEntityStorageBase::resetCache()
TermStorage::resetCache in core/modules/taxonomy/src/TermStorage.php
Resets the entity cache.
UserStorage::deleteRoleReferences in core/modules/user/src/UserStorage.php
Delete role references.
UserStorage::updateLastAccessTimestamp in core/modules/user/src/UserStorage.php
Update the last access timestamp of the user.
UserStorage::updateLastLoginTimestamp in core/modules/user/src/UserStorage.php
Update the last login timestamp of the user.
1 method overrides ContentEntityStorageBase::resetCache()
TermStorage::resetCache in core/modules/taxonomy/src/TermStorage.php
Resets the entity cache.

File

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

Class

ContentEntityStorageBase
Base class for content entity storage handlers.

Namespace

Drupal\Core\Entity

Code

public function resetCache(?array $ids = NULL) {
  if ($ids) {
    parent::resetCache($ids);
    $revisionable = $this->entityType
      ->isRevisionable();
    $cids = $latest_revision_cids = [];
    $revision_cache_tags = [];
    foreach ($ids as $id) {
      $cids[] = $this->buildCacheId($id);
      $latest_revision_cids[] = "latest_revision_id:{$this->entityTypeId}:{$id}";
      // Invalidate related entity revisions in the persistent entity cache.
      if ($revisionable) {
        // Invalidate all revisions of this entity.
        $revision_cache_tags[] = "{$this->entityTypeId}:{$id}:revisions";
      }
    }
    $this->memoryCache
      ->deleteMultiple($latest_revision_cids);
    if ($this->entityType
      ->isPersistentlyCacheable()) {
      $this->cacheBackend
        ->deleteMultiple($cids);
      if ($revision_cache_tags) {
        // Invalidate related entity revisions in the persistent entity cache.
        Cache::invalidateTags($revision_cache_tags);
      }
    }
    if ($this->entityType
      ->isStaticallyCacheable() && $revisionable && $revision_cache_tags) {
      // Invalidate related entity revisions in the memory entity cache.
      $this->memoryCache
        ->invalidateTags($revision_cache_tags);
    }
  }
  else {
    parent::resetCache();
    if ($this->entityType
      ->isPersistentlyCacheable()) {
      $this->cacheBackend
        ->deleteAll();
    }
  }
}

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