diff --git a/core/lib/Drupal/Core/Cache/MemoryBackend.php b/core/lib/Drupal/Core/Cache/MemoryBackend.php index 23fddc5..f0e931b 100644 --- a/core/lib/Drupal/Core/Cache/MemoryBackend.php +++ b/core/lib/Drupal/Core/Cache/MemoryBackend.php @@ -208,6 +208,8 @@ public function garbageCollection() { /** * {@inheritdoc} */ - public function removeBin() {} + public function removeBin() { + $this->cache = []; + } } diff --git a/core/lib/Drupal/Core/Cache/PhpBackend.php b/core/lib/Drupal/Core/Cache/PhpBackend.php index e188ffb..0f3a9b8 100644 --- a/core/lib/Drupal/Core/Cache/PhpBackend.php +++ b/core/lib/Drupal/Core/Cache/PhpBackend.php @@ -240,7 +240,7 @@ public function garbageCollection() { */ public function removeBin() { $this->cache = array(); - $this->storage()->delete($this->bin); + $this->storage()->deleteAll(); } /** diff --git a/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php b/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php index 97d7ccd..2771475 100644 --- a/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php +++ b/core/modules/system/src/Tests/Cache/GenericCacheBackendUnitTestBase.php @@ -666,4 +666,23 @@ public function testInvalidateAll() { $this->assertTrue($backend->get('test2', TRUE), 'Second key has not been deleted.'); } + /** + * Tests Drupal\Core\Cache\CacheBackendInterface::removeBin(). + */ + public function testRemoveBin() { + $backend = $this->getCacheBackend(); + $unrelated = $this->getCacheBackend('bootstrap'); + + // Set both expiring and permanent keys. + $backend->set('test1', 1, Cache::PERMANENT); + $backend->set('test2', 3, time() + 1000); + $unrelated->set('test3', 4, Cache::PERMANENT); + + $backend->removeBin(); + + $this->assertFalse($backend->get('test1'), 'First key has been deleted.'); + $this->assertFalse($backend->get('test2', TRUE), 'Second key has been deleted.'); + $this->assertTrue($unrelated->get('test3'), 'Item in other bin is preserved.'); + } + }