core/lib/Drupal/Core/Config/Config.php | 4 +++- .../Drupal/Core/Config/Entity/ConfigEntityBase.php | 22 ++++++++++++++++++++++ core/lib/Drupal/Core/Entity/Entity.php | 2 +- core/tests/Drupal/Tests/Core/Config/ConfigTest.php | 11 ++++++++--- .../Core/Config/Entity/ConfigEntityStorageTest.php | 16 +++++++++------- 5 files changed, 43 insertions(+), 12 deletions(-) diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index bc6ba29..ed9c28e 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -224,7 +224,9 @@ public function save() { } $this->storage->write($this->name, $this->data); - Cache::invalidateTags($this->getCacheTags()); + if (!$this->isNew) { + Cache::invalidateTags($this->getCacheTags()); + } $this->isNew = FALSE; $this->eventDispatcher->dispatch(ConfigEvents::SAVE, new ConfigCrudEvent($this)); $this->originalData = $this->data; diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 8cca5bd..0304d09 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -14,6 +14,7 @@ use Drupal\Core\Entity\Entity; use Drupal\Core\Config\ConfigDuplicateUUIDException; use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityWithPluginCollectionInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Plugin\PluginDependencyTrait; @@ -420,4 +421,25 @@ public function getConfigDependencyName() { public function onDependencyRemoval(array $dependencies) { } + /** + * {@inheritdoc} + * + * Override to never invalidate the entity's cache tag; the config system + * already invalidates it. + */ + protected function invalidateTagsOnSave($update) { + Cache::invalidateTags($this->getEntityType()->getListCacheTags()); + } + + /** + * {@inheritdoc} + * + * Override to never invalidate the individual entities' cache tags; the + * config system already invalidates them. + + */ + protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities) { + Cache::invalidateTags($entity_type->getListCacheTags()); + } + } diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index c76dc40..d6b78be 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -406,7 +406,7 @@ public static function preDelete(EntityStorageInterface $storage, array $entitie * {@inheritdoc} */ public static function postDelete(EntityStorageInterface $storage, array $entities) { - self::invalidateTagsOnDelete($storage->getEntityType(), $entities); + static::invalidateTagsOnDelete($storage->getEntityType(), $entities); } /** diff --git a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php index 549e28a..fe3c819 100644 --- a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php +++ b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php @@ -151,6 +151,13 @@ public function testSave($data) { // Check that the original data it saved. $this->assertOriginalConfigDataEquals($data, TRUE); + + // The above created a config object; now update it. + $new_data = $data; + $new_data['a']['d'] = 2; + $this->config->setData($new_data); + $this->config->save(); + $this->assertOriginalConfigDataEquals($new_data, TRUE); } /** @@ -293,9 +300,7 @@ public function testNestedClear($data) { * @dataProvider overrideDataProvider */ public function testDelete($data, $module_data) { - // Verifying that invalidateTags() is invoked *twice*: once for saving, once - // for deleting. - $this->cacheTagsInvalidator->expects($this->exactly(2)) + $this->cacheTagsInvalidator->expects($this->once()) ->method('invalidateTags') ->with(['config:config.test']); diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php index 4781dbe..f7eef52 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php @@ -302,8 +302,9 @@ public function testSaveUpdate(EntityInterface $entity) { $this->cacheTagsInvalidator->expects($this->once()) ->method('invalidateTags') ->with(array( - 'config:the_config_prefix.foo', // Own cache tag. - $this->entityTypeId . '_list', // List cache tag. + // List cache tag only; the own cache tag is invalidated by the config + // system. + $this->entityTypeId . '_list', )); $this->configFactory->expects($this->exactly(2)) @@ -362,8 +363,9 @@ public function testSaveRename(ConfigEntityInterface $entity) { $this->cacheTagsInvalidator->expects($this->once()) ->method('invalidateTags') ->with(array( - 'config:the_config_prefix.bar', // Own cache tag. - $this->entityTypeId . '_list', // List cache tag. + // List cache tag only; the own cache tag is invalidated by the config + // system. + $this->entityTypeId . '_list', )); $this->configFactory->expects($this->once()) @@ -728,9 +730,9 @@ public function testDelete() { $this->cacheTagsInvalidator->expects($this->once()) ->method('invalidateTags') ->with(array( - 'config:the_config_prefix.bar', // Own cache tag. - 'config:the_config_prefix.foo', // Own cache tag. - $this->entityTypeId . '_list', // List cache tag. + // List cache tag only; the own cache tag is invalidated by the config + // system. + $this->entityTypeId . '_list', )); $this->configFactory->expects($this->exactly(2))