function ChainedFastBackendTest::testLastWriteTimestampMissing
Same name and namespace in other branches
- main core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php \Drupal\Tests\Core\Cache\ChainedFastBackendTest::testLastWriteTimestampMissing()
Tests last_write_timestamp missing from the consistent backend.
File
-
core/
tests/ Drupal/ Tests/ Core/ Cache/ ChainedFastBackendTest.php, line 248
Class
Namespace
Drupal\Tests\Core\CacheCode
public function testLastWriteTimestampMissing() : void {
$timestamp_cid = ChainedFastBackend::LAST_WRITE_TIMESTAMP_PREFIX . 'cache_foo';
$cache_item = (object) [
'cid' => 'foo',
'data' => 'baz',
'created' => time(),
'expire' => time() + 3600,
'tags' => [
'tag',
],
];
$consistent_cache = $this->createMock(CacheBackendInterface::class);
$fast_cache = $this->createMock(CacheBackendInterface::class);
// Simulate the last_write_timestamp being unset on the consistent backend.
$consistent_cache->expects($this->once())
->method('get')
->with($timestamp_cid)
->willReturn(NULL);
// Because the last_write_timestamp was missing, it will be newly set on the
// consistent backend.
$consistent_cache->expects($this->once())
->method('set')
->with($timestamp_cid);
$consistent_cache->expects($this->once())
->method('getMultiple')
->with([
$cache_item->cid,
])
->willReturn([
$cache_item->cid => $cache_item,
]);
// We should not get a call for the cache item on the fast backend but
// because the last_write_timestamp is now in place, the item from the
// consistent backend should be written back.
$fast_cache->expects($this->never())
->method('getMultiple');
$fast_cache->expects($this->once())
->method('set')
->with($cache_item->cid);
$chained_fast_backend = new ChainedFastBackend($consistent_cache, $fast_cache, 'foo');
$this->assertEquals('baz', $chained_fast_backend->get('foo')->data);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.