diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index ba8bbdb801..678683fdac 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -487,8 +487,7 @@ public function onDependencyRemoval(array $dependencies) { * already invalidates it. */ protected function invalidateTagsOnSave($update) { - $tags = Cache::mergeTags($this->getEntityType()->getListCacheTags(), $this->getListCacheTags()); - Cache::invalidateTags($tags); + Cache::invalidateTags($this->getListCacheTags()); } /** @@ -498,10 +497,13 @@ protected function invalidateTagsOnSave($update) { * config system already invalidates them. */ protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities) { - $tags = $entity_type->getListCacheTags(); + $tags = []; foreach ($entities as $entity) { $tags = Cache::mergeTags($tags, $entity->getListCacheTags()); } + if (empty($entities)) { + $tags = $entity_type->getListCacheTags(); + } Cache::invalidateTags($tags); } diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 922b47da70..fb4c7d9011 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -590,7 +590,7 @@ protected function invalidateTagsOnSave($update) { * An array of entities. */ protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities) { - $tags = $entity_type->getListCacheTags(); + $tags = []; foreach ($entities as $entity) { // An entity was deleted: invalidate its own cache tag, but also its list // cache tags. (A deleted entity may cause changes in a paged list on @@ -600,6 +600,9 @@ protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_typ $tags = Cache::mergeTags($tags, $entity->getCacheTagsToInvalidate()); $tags = Cache::mergeTags($tags, $entity->getListCacheTags()); } + if (empty($entities)) { + $tags = $entity_type->getListCacheTags(); + } Cache::invalidateTags($tags); } diff --git a/core/modules/system/tests/modules/entity_test/src/Controller/EntityTestController.php b/core/modules/system/tests/modules/entity_test/src/Controller/EntityTestController.php index 8a96049060..6c5e6cd287 100644 --- a/core/modules/system/tests/modules/entity_test/src/Controller/EntityTestController.php +++ b/core/modules/system/tests/modules/entity_test/src/Controller/EntityTestController.php @@ -80,6 +80,11 @@ public function listEntitiesAlphabetically($entity_type_id) { $cache_tags = Cache::mergeTags($cache_tags, $entity->getCacheTags()); $cache_tags = Cache::mergeTags($cache_tags, $entity->getListCacheTags()); } + if (empty($entities)) { + // Always associate the list cache tag with empty result, otherwise the + // cached empty result wouldn't be invalidated. + $cache_tags = Cache::mergeTags($cache_tags, $entity_type_definition->getListCacheTags()); + } return [ '#theme' => 'item_list',