function CacheCollectorTest::testUpdateCacheClearTags
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php \Drupal\Tests\Core\Cache\CacheCollectorTest::testUpdateCacheClearTags()
- 8.9.x core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php \Drupal\Tests\Core\Cache\CacheCollectorTest::testUpdateCacheClearTags()
- 11.x core/tests/Drupal/Tests/Core/Cache/CacheCollectorTest.php \Drupal\Tests\Core\Cache\CacheCollectorTest::testUpdateCacheClearTags()
Tests a clear of the cache collector using tags.
File
-
core/
tests/ Drupal/ Tests/ Core/ Cache/ CacheCollectorTest.php, line 420
Class
- CacheCollectorTest
- @coversDefaultClass \Drupal\Core\Cache\CacheCollector @group Cache
Namespace
Drupal\Tests\Core\CacheCode
public function testUpdateCacheClearTags() : void {
$key = $this->randomMachineName();
$value = $this->randomMachineName();
$tags = [
$this->randomMachineName(),
];
$this->collector = new CacheCollectorHelper($this->cid, $this->cacheBackend, $this->lock, $tags);
// Set the data and request it.
$this->collector
->setCacheMissData($key, $value);
$this->assertEquals($value, $this->collector
->get($key));
$this->assertEquals($value, $this->collector
->get($key));
// Should have been added to the storage and only be requested once.
$this->assertEquals(1, $this->collector
->getCacheMisses());
// Clear the collected cache using the tags, should call it again.
$this->cacheBackend
->expects($this->never())
->method('delete');
$this->cacheTagsInvalidator
->expects($this->once())
->method('invalidateTags')
->with($tags);
$this->collector
->clear();
$this->assertEquals($value, $this->collector
->get($key));
$this->assertEquals(2, $this->collector
->getCacheMisses());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.