function ChainedFastBackendTest::testFallThroughToConsistentCache

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php \Drupal\Tests\Core\Cache\ChainedFastBackendTest::testFallThroughToConsistentCache()
  2. 8.9.x core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php \Drupal\Tests\Core\Cache\ChainedFastBackendTest::testFallThroughToConsistentCache()
  3. 11.x core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php \Drupal\Tests\Core\Cache\ChainedFastBackendTest::testFallThroughToConsistentCache()

Tests a fast cache miss gets data from the consistent cache backend.

File

core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendTest.php, line 67

Class

ChainedFastBackendTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Cache%21ChainedFastBackend.php/class/ChainedFastBackend/10" title="Defines a backend with a fast and a consistent backend chain." class="local">\Drupal\Core\Cache\ChainedFastBackend</a> @group Cache

Namespace

Drupal\Tests\Core\Cache

Code

public function testFallThroughToConsistentCache() : void {
    $timestamp_item = (object) [
        'cid' => ChainedFastBackend::LAST_WRITE_TIMESTAMP_PREFIX . 'cache_foo',
        // Time travel is easy.
'data' => time() + 60,
    ];
    $cache_item = (object) [
        'cid' => 'foo',
        'data' => 'baz',
        'created' => time(),
        'expire' => time() + 3600,
        'tags' => [
            'tag',
        ],
    ];
    $consistent_cache = $this->createMock('Drupal\\Core\\Cache\\CacheBackendInterface');
    $fast_cache = $this->createMock('Drupal\\Core\\Cache\\CacheBackendInterface');
    // 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.