function MemCacheClearCase::testClearCacheLifetime in Memcache API and Integration 7
Same name in this branch
- 7 tests/memcache.test \MemCacheClearCase::testClearCacheLifetime()
- 7 tests/memcache6.test \MemCacheClearCase::testClearCacheLifetime()
Same name and namespace in other branches
- 6 tests/memcache.test \MemCacheClearCase::testClearCacheLifetime()
Test full bin flushes with cache lifetime.
File
- tests/
memcache6.test, line 242
Class
- MemCacheClearCase
- Test cache clearing methods.
Code
function testClearCacheLifetime() {
variable_set("cache_flush_{$this->default_bin}", 0);
variable_set('cache_lifetime', 600);
// 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();
// 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_1', $this->default_value, $this->default_bin, time() + 6000);
$this
->assertTrue($this
->checkCacheExists('test_cid', $this->default_value), 'Cache item was created successfully.');
sleep(2);
cache_clear_all();
$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);
sleep(1);
// 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.');
}