You are here

public function MemCacheClearCase::testClearCacheLifetime in Memcache API and Integration 7

Same name in this branch
  1. 7 tests/memcache.test \MemCacheClearCase::testClearCacheLifetime()
  2. 7 tests/memcache6.test \MemCacheClearCase::testClearCacheLifetime()
Same name and namespace in other branches
  1. 6 tests/memcache.test \MemCacheClearCase::testClearCacheLifetime()

Test full bin flushes with cache lifetime.

File

tests/memcache.test, line 489
Test cases for the memcache cache backend.

Class

MemCacheClearCase
Test cache clearing methods.

Code

public function testClearCacheLifetime() {
  variable_set('cache_lifetime', 600);
  $this
    ->resetVariables();

  // Set a cache item with an expiry.
  cache_set('test_cid', $this->default_value, $this->default_bin, time() + 3600);
  $this
    ->assertTrue($this
    ->checkCacheExists('test_cid', $this->default_value), 'Cache item was created successfully.');

  // Set a permanent cache item.
  cache_set('test_cid_2', $this->default_value, $this->default_bin);

  // Clear the page and block caches.
  cache_clear_all(MEMCACHE_CONTENT_CLEAR, $this->default_bin);

  // Since the cache was cleared within the current session, cache_get()
  // should return false.
  $this
    ->assertFalse($this
    ->checkCacheExists('test_cid', $this->default_value), 'Cache item was cleared successfully.');

  // However permament items should stay in place.
  $this
    ->assertTrue($this
    ->checkCacheExists('test_cid_2', $this->default_value), 'Cache item was not cleared');

  // If $_SESSION['cache_flush'] is not set, then the expired item should
  // be returned.
  unset($_SESSION['cache_flush']);
  $this
    ->assertTrue($this
    ->checkCacheExists('test_cid', $this->default_value), 'Cache item is still returned due to minimum cache lifetime.');

  // Set a much shorter cache lifetime.
  variable_set('cache_content_flush_' . $this->default_bin, 0);
  variable_set('cache_lifetime', 1);
  cache_set('test_cid', $this->default_value, $this->default_bin, time() + 6000);
  $this
    ->assertTrue($this
    ->checkCacheExists('test_cid', $this->default_value), 'Cache item was created successfully.');
  cache_clear_all(MEMCACHE_CONTENT_CLEAR, $this->default_bin);
  $this
    ->assertFalse($this
    ->checkCacheExists('test_cid', $this->default_value), 'Cache item is not returned once minimum cache lifetime has expired.');

  // Reset the cache clear variables.
  variable_set('cache_content_flush_' . $this->default_bin, 0);
  variable_set('cache_lifetime', 6000);
  $this
    ->resetVariables();

  // Confirm that cache_lifetime does not take effect for full bin flushes.
  cache_set('test_cid', $this->default_value, $this->default_bin, time() + 6000);
  $this
    ->assertTrue($this
    ->checkCacheExists('test_cid', $this->default_value), 'Cache item was created successfully.');
  cache_set('test_cid_2', $this->default_value, $this->default_bin);
  $this
    ->assertTrue($this
    ->checkCacheExists('test_cid_2', $this->default_value), 'Cache item was created successfully.');

  // Now flush the bin.
  cache_clear_all('*', $this->default_bin, TRUE);
  $this
    ->assertFalse($this
    ->checkCacheExists('test_cid', $this->default_value), 'Cache item was cleared successfully.');
  $this
    ->assertFalse($this
    ->checkCacheExists('test_cid_2', $this->default_value), 'Cache item was cleared successfully.');
}