function EntityViewBuilder::resetCache

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Entity/EntityViewBuilder.php \Drupal\Core\Entity\EntityViewBuilder::resetCache()
  2. 10 core/lib/Drupal/Core/Entity/EntityViewBuilder.php \Drupal\Core\Entity\EntityViewBuilder::resetCache()
  3. 11.x core/lib/Drupal/Core/Entity/EntityViewBuilder.php \Drupal\Core\Entity\EntityViewBuilder::resetCache()

Overrides EntityViewBuilderInterface::resetCache

File

core/lib/Drupal/Core/Entity/EntityViewBuilder.php, line 402

Class

EntityViewBuilder
Base class for entity view builders.

Namespace

Drupal\Core\Entity

Code

public function resetCache(array $entities = NULL) {
    // If no set of specific entities is provided, invalidate the entity view
    // builder's cache tag. This will invalidate all entities rendered by this
    // view builder.
    // Otherwise, if a set of specific entities is provided, invalidate those
    // specific entities only, plus their list cache tags, because any lists in
    // which these entities are rendered, must be invalidated as well. However,
    // even in this case, we might invalidate more cache items than necessary.
    // When we have a way to invalidate only those cache items that have both
    // the individual entity's cache tag and the view builder's cache tag, we'll
    // be able to optimize this further.
    if (isset($entities)) {
        $tags = [];
        foreach ($entities as $entity) {
            $tags = Cache::mergeTags($tags, $entity->getCacheTags());
            $tags = Cache::mergeTags($tags, $entity->getEntityType()
                ->getListCacheTags());
        }
        Cache::invalidateTags($tags);
    }
    else {
        Cache::invalidateTags($this->getCacheTags());
    }
}

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