function ChainedFastBackendTest::testFallThroughToConsistentCache
Tests a fast cache miss gets data from the consistent cache backend.
File
-
core/
tests/ Drupal/ Tests/ Core/ Cache/ ChainedFastBackendTest.php, line 192
Class
Namespace
Drupal\Tests\Core\CacheCode
public function testFallThroughToConsistentCache() : void {
// Make the last_write_timestamp two seconds in the past so that everything
// is written back to the fast backend.
$timestamp_item = (object) [
'cid' => ChainedFastBackend::LAST_WRITE_TIMESTAMP_PREFIX . 'cache_foo',
'data' => time() - 2,
];
$cache_item = (object) [
'cid' => 'foo',
'data' => 'baz',
// The created time is set one minute in the past, e.g. before the
// consistent timestamp.
'created' => time() - 60,
'expire' => time() + 3600,
'tags' => [
'tag',
],
];
$consistent_cache = $this->createMock(CacheBackendInterface::class);
$fast_cache = $this->createMock(CacheBackendInterface::class);
// We should get a call for the timestamp on the consistent backend.
$consistent_cache->expects($this->once())
->method('get')
->with($timestamp_item->cid)
->willReturn($timestamp_item);
// We should get a call for the cache item on the consistent backend.
$consistent_cache->expects($this->once())
->method('getMultiple')
->with([
$cache_item->cid,
])
->willReturn([
$cache_item->cid => $cache_item,
]);
// We should get a call for the cache item on the fast backend.
$fast_cache->expects($this->once())
->method('getMultiple')
->with([
$cache_item->cid,
])
->willReturn([
$cache_item->cid => $cache_item,
]);
// We should get a call to set the cache item on the fast backend.
$fast_cache->expects($this->once())
->method('set')
->with($cache_item->cid, $cache_item->data, $cache_item->expire);
$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.