diff --git a/core/lib/Drupal/Core/Utility/CacheArray.php b/core/lib/Drupal/Core/Utility/CacheArray.php index 65c0508..3e6c914 100644 --- a/core/lib/Drupal/Core/Utility/CacheArray.php +++ b/core/lib/Drupal/Core/Utility/CacheArray.php @@ -95,6 +95,13 @@ protected $keysToPersist = array(); /** + * An array of keys to remove from the cache at the end of the request. + * + * @var array + */ + protected $keysToRemove = array(); + + /** * Storage for the data itself. * * @var array @@ -152,6 +159,9 @@ public function offsetSet($offset, $value) { */ public function offsetUnset($offset) { unset($this->storage[$offset]); + $this->keysToRemove[$offset] = $offset; + // The offset might have been marked for persisting. + unset($this->keysToPersist[$offset]); } /** @@ -171,6 +181,8 @@ public function offsetUnset($offset) { */ protected function persist($offset, $persist = TRUE) { $this->keysToPersist[$offset] = $persist; + // The offset might have been marked for deletion. + unset($this->keysToRemove[$offset]); } /** @@ -204,6 +216,10 @@ protected function setData($data, $lock = TRUE) { if ($cached = cache($this->bin)->get($this->cid)) { $data = $cached->data + $data; } + // Remove keys marked for deletion. + foreach ($this->keysToRemove as $delete_key) { + unset($data[$delete_key]); + } cache($this->bin)->set($this->cid, $data, CacheBackendInterface::CACHE_PERMANENT, $this->tags); if ($lock) { lock()->release($lock_name);