diff --git a/core/modules/system/src/Tests/Cache/ChainedFastBackendUnitTest.php b/core/modules/system/src/Tests/Cache/ChainedFastBackendUnitTest.php index c34563c..9190ca5 100644 --- a/core/modules/system/src/Tests/Cache/ChainedFastBackendUnitTest.php +++ b/core/modules/system/src/Tests/Cache/ChainedFastBackendUnitTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\Cache; +use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Cache\ChainedFastBackend; use Drupal\Core\Cache\DatabaseBackend; use Drupal\Core\Cache\PhpBackend; @@ -34,4 +35,33 @@ protected function createCacheBackend($bin) { return $backend; } + /** + * Test permanent TTL. + */ + function testPermanentTtl() { + $bin = 'test'; + $consistent_backend = new DatabaseBackend(\Drupal::service('database'), \Drupal::service('cache_tags.invalidator.checksum'), $bin); + $consistent_backend->setPermanentTtl(4); + // Since we're using two database backends, we need to provide a different + // bin name to avoid reading to and writing from the same table. + $fast_backend = new DatabaseBackend(\Drupal::service('database'), \Drupal::service('cache_tags.invalidator.checksum'), $bin . '_2'); + $fast_backend->setPermanentTtl(2); + $backend = new ChainedFastBackend($consistent_backend, $fast_backend, $bin); + $cid = 'test'; + $value = 'test'; + $backend->set($cid, $value); + + // The item expiry will be taken from the fast backend, so reflects the + // settings on that backend. + $item = $backend->get($cid); + $this->assertTrue($item->expire <= REQUEST_TIME + 2 * DatabaseBackend::JITTER_MULTIPLIER); + $this->assertTrue($item->expire >= REQUEST_TIME + 2); + $item = $consistent_backend->get($cid); + $this->assertTrue($item->expire <= REQUEST_TIME + 4 * DatabaseBackend::JITTER_MULTIPLIER); + $this->assertTrue($item->expire >= REQUEST_TIME + 4); + $item = $fast_backend->get($cid); + $this->assertTrue($item->expire <= REQUEST_TIME + 2 * DatabaseBackend::JITTER_MULTIPLIER); + $this->assertTrue($item->expire >= REQUEST_TIME + 2); + } + }