You are here

public function CacheTest::testDeleteAllAndNamespaceVersioningBetweenCaches in Zircon Profile 8.0

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

File

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

Class

CacheTest

Namespace

Doctrine\Tests\Common\Cache

Code

public function testDeleteAllAndNamespaceVersioningBetweenCaches() {
  if (!$this
    ->isSharedStorage()) {
    $this
      ->markTestSkipped('The ' . __CLASS__ . ' does not use shared storage');
  }
  $cache1 = $this
    ->_getCacheDriver();
  $cache2 = $this
    ->_getCacheDriver();
  $this
    ->assertTrue($cache1
    ->save('key1', 1));
  $this
    ->assertTrue($cache2
    ->save('key2', 2));

  /* Both providers are initialized with the same namespace version, so
   * they can see entries set by each other.
   */
  $this
    ->assertTrue($cache1
    ->contains('key1'));
  $this
    ->assertTrue($cache1
    ->contains('key2'));
  $this
    ->assertTrue($cache2
    ->contains('key1'));
  $this
    ->assertTrue($cache2
    ->contains('key2'));

  /* Deleting all entries through one provider will only increment the
   * namespace version on that object (and in the cache itself, which new
   * instances will use to initialize). The second provider will retain
   * its original version and still see stale data.
   */
  $this
    ->assertTrue($cache1
    ->deleteAll());
  $this
    ->assertFalse($cache1
    ->contains('key1'));
  $this
    ->assertFalse($cache1
    ->contains('key2'));
  $this
    ->assertTrue($cache2
    ->contains('key1'));
  $this
    ->assertTrue($cache2
    ->contains('key2'));

  /* A new cache provider should not see the deleted entries, since its
   * namespace version will be initialized.
   */
  $cache3 = $this
    ->_getCacheDriver();
  $this
    ->assertFalse($cache3
    ->contains('key1'));
  $this
    ->assertFalse($cache3
    ->contains('key2'));
}