public function ApdqcCacheClearCase::testCacheTemporary in Asynchronous Prefetch Database Query Cache 7
Tests CACHE_TEMPORARY behavior.
File
- ./
apdqc.test, line 163 - Tests for the Asynchronous Prefetch Database Query Cache module.
Class
- ApdqcCacheClearCase
- Test cache clearing methods for APDQC.
Code
public function testCacheTemporary() {
$cache = new APDQCache($this->defaultBin);
// Set a permanent and temporary cache item.
$cache
->set('test_cache_temporary', $this->defaultValue, CACHE_TEMPORARY);
$cache
->set('test_cache_permanent', $this->defaultValue);
// Also set expired and yet to expire cache items.
$cache
->set('test_cache_expired', $this->defaultValue, REQUEST_TIME - 1000);
$cache
->set('test_cache_not_expired', $this->defaultValue, REQUEST_TIME + 1000);
// Run Tests.
$this
->assertTrue($this
->checkCacheExists('test_cache_expired', $this->defaultValue), 'cache_expired set');
$this
->assertTrue($this
->checkCacheExists('test_cache_temporary', $this->defaultValue), 'cache_temporary set');
$this
->assertTrue($this
->checkCacheExists('test_cache_permanent', $this->defaultValue), 'cache_permanent set');
$this
->assertTrue($this
->checkCacheExists('test_cache_not_expired', $this->defaultValue), 'cache_not_expired set');
// Clear all items in the bin. Only the temporary and expired items should
// be removed.
$cache
->clear();
// Run Tests.
$this
->assertFalse($this
->checkCacheExists('test_cache_expired', $this->defaultValue), 'cache_expired removed after a clear');
$this
->assertFalse($this
->checkCacheExists('test_cache_temporary', $this->defaultValue), 'cache_temporary removed after a clear');
$this
->assertTrue($this
->checkCacheExists('test_cache_permanent', $this->defaultValue), 'cache_permanent still set after a clear');
$this
->assertTrue($this
->checkCacheExists('test_cache_not_expired', $this->defaultValue), 'cache_not_expired still set after a clear');
// Re-add the items we just cleared.
$cache
->set('test_cache_temporary', $this->defaultValue, CACHE_TEMPORARY);
$cache
->set('test_cache_expired', $this->defaultValue, REQUEST_TIME - 1000);
// Set a minimum cache lifetime.
$this
->setupLifetime(300);
// Now after clearing the bin, only the expired item should be removed.
$cache
->clear();
// Run Tests.
$this
->assertFalse($this
->checkCacheExists('test_cache_expired', $this->defaultValue), 'cache_expired removed after a clear with min lifetime');
$this
->assertTrue($this
->checkCacheExists('test_cache_temporary', $this->defaultValue), 'cache_temporary still set after a clear with min lifetime');
$this
->assertTrue($this
->checkCacheExists('test_cache_permanent', $this->defaultValue), 'cache_permanent still set after a clear with min lifetime');
$this
->assertTrue($this
->checkCacheExists('test_cache_not_expired', $this->defaultValue), 'cache_not_expired still set after a clear with min lifetime');
}