diff --git a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php index 5eb5c30..21cb79f 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php @@ -312,6 +312,11 @@ protected function doPostSave(EntityInterface $entity, $update) { if ($this->entityType->isRevisionable()) { $entity->setNewRevision(FALSE); } + + // Reset the persistent cache if this entity type uses it. + if ($update) { + $this->clearPersistentCache([$entity]); + } } /** @@ -323,6 +328,9 @@ protected function doDelete($entities) { $this->invokeFieldMethod('delete', $entity); } $this->doDeleteFieldItems($entities); + + // Reset the persistent cache if this entity type uses it. + $this->clearPersistentCache($entities); } /** @@ -608,24 +616,41 @@ protected function setPersistentCache($entities) { } /** + * Clears the persistent cache for an entity if it uses persistent caching. + * + * @param \Drupal\Core\Entity\EntityInterface[] $entities + */ + protected function clearPersistentCache(array $entities = NULL) { + if (!$this->entityType->isPersistentlyCacheable()) { + return; + } + + if (isset($entities)) { + $cache_ids = []; + foreach ($entities as $entity) { + if (!$entity->isNew()) { + $cache_ids[] = $this->buildCacheId($entity->id()); + } + } + + $this->cacheBackend->deleteMultiple($cache_ids); + } + else { + Cache::invalidateTags(array($this->entityTypeId . '_values')); + } + } + + /** * {@inheritdoc} */ public function resetCache(array $ids = NULL) { if ($ids) { - $cids = array(); foreach ($ids as $id) { unset($this->entities[$id]); - $cids[] = $this->buildCacheId($id); - } - if ($this->entityType->isPersistentlyCacheable()) { - $this->cacheBackend->deleteMultiple($cids); } } else { $this->entities = array(); - if ($this->entityType->isPersistentlyCacheable()) { - Cache::invalidateTags(array($this->entityTypeId . '_values')); - } } }