You are here

public function CacheTest::testFlushAllAndNamespaceVersioningBetweenCaches in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/CacheTest.php \Doctrine\Tests\Common\Cache\CacheTest::testFlushAllAndNamespaceVersioningBetweenCaches()

File

vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/CacheTest.php, line 158

Class

CacheTest

Namespace

Doctrine\Tests\Common\Cache

Code

public function testFlushAllAndNamespaceVersioningBetweenCaches() {
  if (!$this
    ->isSharedStorage()) {
    $this
      ->markTestSkipped('The ' . __CLASS__ . ' does not use shared storage');
  }
  $cache1 = $this
    ->_getCacheDriver();
  $cache2 = $this
    ->_getCacheDriver();

  /* Deleting all elements from the first provider should increment its
   * namespace version before saving the first entry.
   */
  $cache1
    ->deleteAll();
  $this
    ->assertTrue($cache1
    ->save('key1', 1));

  /* The second provider will be initialized with the same namespace
   * version upon its first save operation.
   */
  $this
    ->assertTrue($cache2
    ->save('key2', 2));

  /* Both providers have the same namespace version and can see entires
   * set by each other.
   */
  $this
    ->assertTrue($cache1
    ->contains('key1'));
  $this
    ->assertTrue($cache1
    ->contains('key2'));
  $this
    ->assertTrue($cache2
    ->contains('key1'));
  $this
    ->assertTrue($cache2
    ->contains('key2'));

  /* Flushing all entries through one cache will remove all entries from
   * the cache but leave their namespace version as-is.
   */
  $this
    ->assertTrue($cache1
    ->flushAll());
  $this
    ->assertFalse($cache1
    ->contains('key1'));
  $this
    ->assertFalse($cache1
    ->contains('key2'));
  $this
    ->assertFalse($cache2
    ->contains('key1'));
  $this
    ->assertFalse($cache2
    ->contains('key2'));

  /* Inserting a new entry will use the same, incremented namespace
   * version, and it will be visible to both providers.
   */
  $this
    ->assertTrue($cache1
    ->save('key1', 1));
  $this
    ->assertTrue($cache1
    ->contains('key1'));
  $this
    ->assertTrue($cache2
    ->contains('key1'));

  /* A new cache provider will be initialized with the original namespace
   * version and not share any visibility with the first two providers.
   */
  $cache3 = $this
    ->_getCacheDriver();
  $this
    ->assertFalse($cache3
    ->contains('key1'));
  $this
    ->assertFalse($cache3
    ->contains('key2'));
  $this
    ->assertTrue($cache3
    ->save('key3', 3));
  $this
    ->assertTrue($cache3
    ->contains('key3'));
}