public function BackendChainImplementationUnitTest::testDeleteTagsPropagation in Zircon Profile 8
Same name and namespace in other branches
- 8.0 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 219 - Contains \Drupal\Tests\Core\Cache\BackendChainImplementationUnitTest.
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, array(
'test_tag:2',
));
$this->chain
->set('test_cid_clear2', 'foo', Cache::PERMANENT, array(
'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(array(
'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, array(
'test_tag:1',
));
$this->chain
->set('test_cid_clear2', 'foo', Cache::PERMANENT, array(
'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(array(
'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, array(
'test_tag:1',
));
$this->chain
->set('test_cid_clear2', 'foo', Cache::PERMANENT, array(
'test_tag:2',
));
$this->chain
->set('test_cid_clear3', 'foo', Cache::PERMANENT, array(
'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(array(
'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.');
}