function BackendChainImplementationUnitTest::testDeleteTagsPropagation
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php \Drupal\Tests\Core\Cache\BackendChainImplementationUnitTest::testDeleteTagsPropagation()
- 10 core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php \Drupal\Tests\Core\Cache\BackendChainImplementationUnitTest::testDeleteTagsPropagation()
- 11.x core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php \Drupal\Tests\Core\Cache\BackendChainImplementationUnitTest::testDeleteTagsPropagation()
Test that the delete tags operation is propagated to all backends in the chain.
File
-
core/
tests/ Drupal/ Tests/ Core/ Cache/ BackendChainImplementationUnitTest.php, line 215
Class
- BackendChainImplementationUnitTest
- Unit test of backend chain implementation specifics.
Namespace
Drupal\Tests\Core\CacheCode
public function testDeleteTagsPropagation() {
// Create two cache entries with the same tag and tag value.
$this->chain
->set('test_cid_clear1', 'foo', Cache::PERMANENT, [
'test_tag:2',
]);
$this->chain
->set('test_cid_clear2', 'foo', Cache::PERMANENT, [
'test_tag:2',
]);
$this->assertNotSame(FALSE, $this->firstBackend
->get('test_cid_clear1') && $this->firstBackend
->get('test_cid_clear2') && $this->secondBackend
->get('test_cid_clear1') && $this->secondBackend
->get('test_cid_clear2') && $this->thirdBackend
->get('test_cid_clear1') && $this->thirdBackend
->get('test_cid_clear2'), 'Two cache items were created in all backends.');
// Invalidate test_tag of value 1. This should invalidate both entries.
$this->chain
->invalidateTags([
'test_tag:2',
]);
$this->assertSame(FALSE, $this->firstBackend
->get('test_cid_clear1') && $this->firstBackend
->get('test_cid_clear2') && $this->secondBackend
->get('test_cid_clear1') && $this->secondBackend
->get('test_cid_clear2') && $this->thirdBackend
->get('test_cid_clear1') && $this->thirdBackend
->get('test_cid_clear2'), 'Two caches removed from all backends after clearing a cache tag.');
// Create two cache entries with the same tag and an array tag value.
$this->chain
->set('test_cid_clear1', 'foo', Cache::PERMANENT, [
'test_tag:1',
]);
$this->chain
->set('test_cid_clear2', 'foo', Cache::PERMANENT, [
'test_tag:1',
]);
$this->assertNotSame(FALSE, $this->firstBackend
->get('test_cid_clear1') && $this->firstBackend
->get('test_cid_clear2') && $this->secondBackend
->get('test_cid_clear1') && $this->secondBackend
->get('test_cid_clear2') && $this->thirdBackend
->get('test_cid_clear1') && $this->thirdBackend
->get('test_cid_clear2'), 'Two cache items were created in all backends.');
// Invalidate test_tag of value 1. This should invalidate both entries.
$this->chain
->invalidateTags([
'test_tag:1',
]);
$this->assertSame(FALSE, $this->firstBackend
->get('test_cid_clear1') && $this->firstBackend
->get('test_cid_clear2') && $this->secondBackend
->get('test_cid_clear1') && $this->secondBackend
->get('test_cid_clear2') && $this->thirdBackend
->get('test_cid_clear1') && $this->thirdBackend
->get('test_cid_clear2'), 'Two caches removed from all backends after clearing a cache tag.');
// Create three cache entries with a mix of tags and tag values.
$this->chain
->set('test_cid_clear1', 'foo', Cache::PERMANENT, [
'test_tag:1',
]);
$this->chain
->set('test_cid_clear2', 'foo', Cache::PERMANENT, [
'test_tag:2',
]);
$this->chain
->set('test_cid_clear3', 'foo', Cache::PERMANENT, [
'test_tag_foo:3',
]);
$this->assertNotSame(FALSE, $this->firstBackend
->get('test_cid_clear1') && $this->firstBackend
->get('test_cid_clear2') && $this->firstBackend
->get('test_cid_clear3') && $this->secondBackend
->get('test_cid_clear1') && $this->secondBackend
->get('test_cid_clear2') && $this->secondBackend
->get('test_cid_clear3') && $this->thirdBackend
->get('test_cid_clear1') && $this->thirdBackend
->get('test_cid_clear2') && $this->thirdBackend
->get('test_cid_clear3'), 'Three cached items were created in all backends.');
$this->chain
->invalidateTags([
'test_tag_foo:3',
]);
$this->assertNotSame(FALSE, $this->firstBackend
->get('test_cid_clear1') && $this->firstBackend
->get('test_cid_clear2') && $this->secondBackend
->get('test_cid_clear1') && $this->secondBackend
->get('test_cid_clear2') && $this->thirdBackend
->get('test_cid_clear1') && $this->thirdBackend
->get('test_cid_clear2'), 'Cached items not matching the tag were not cleared from any of the backends.');
$this->assertSame(FALSE, $this->firstBackend
->get('test_cid_clear3') && $this->secondBackend
->get('test_cid_clear3') && $this->thirdBackend
->get('test_cid_clear3'), 'Cached item matching the tag was removed from all backends.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.