diff --git a/core/lib/Drupal/Core/KeyValueStore/KeyValueCacheDecorator.php b/core/lib/Drupal/Core/KeyValueStore/KeyValueCacheDecorator.php index 2c09d7b..df6e074 100644 --- a/core/lib/Drupal/Core/KeyValueStore/KeyValueCacheDecorator.php +++ b/core/lib/Drupal/Core/KeyValueStore/KeyValueCacheDecorator.php @@ -37,6 +37,9 @@ protected function resolveCacheMiss($offset) { public function delete($key) { parent::delete($key); $this->keyValueStore->delete($key); + // Delete the cache to make sure that other requests immediately see the new + // value before this request is terminated. + $this->cache->delete($this->cid); } public function deleteMultiple(array $keys) { @@ -44,6 +47,9 @@ public function deleteMultiple(array $keys) { $this->delete($key); } $this->keyValueStore->deleteMultiple($keys); + // Delete the cache to make sure that other requests immediately see the new + // value before this request is terminated. + $this->cache->delete($this->cid); } public function getAll() { @@ -73,14 +79,18 @@ public function setMultiple(array $data) { $this->keyValueStore->setMultiple($data); foreach ($data as $key => $value) { parent::set($key, $value); - $this->persist($key); } + // Delete the cache to make sure that other requests immediately see the new + // value before this request is terminated. + $this->cache->delete($this->cid); } public function set($key, $value) { $this->keyValueStore->set($key, $value); parent::set($key, $value); - $this->persist($key); + // Delete the cache to make sure that other requests immediately see the new + // value before this request is terminated. + $this->cache->delete($this->cid); } /** diff --git a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php index 4531c9f..0788b38 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php @@ -143,6 +143,18 @@ public function containerBuild($container) { $container ->register('keyvalue', 'Drupal\Core\KeyValueStore\KeyValueFactory') ->addArgument(new Reference('service_container')); + + $container + ->register('cache.cache', 'Drupal\Core\Cache\CacheBackendInterface') + ->setFactoryClass('Drupal\Core\Cache\CacheFactory') + ->setFactoryMethod('get') + ->addArgument('cache'); + + $container->register('state', 'Drupal\Core\KeyValueStore\KeyValueCacheDecorator') + ->addArgument(new Reference('cache.cache')) + ->addArgument(new Reference('lock')) + ->addArgument(new Reference('keyvalue')) + ->addArgument('state'); } }