public function ApdqcCacheClearCase::testMinimumCacheLifetime in Asynchronous Prefetch Database Query Cache 7
Test minimum cache lifetime.
File
- ./
apdqc.test, line 243 - Tests for the Asynchronous Prefetch Database Query Cache module.
Class
- ApdqcCacheClearCase
- Test cache clearing methods for APDQC.
Code
public function testMinimumCacheLifetime() {
// Set a minimum/maximum cache lifetime.
$this
->setupLifetime(300);
// Login as a newly-created user.
$account = $this
->drupalCreateUser(array());
$this
->drupalLogin($account);
// Set two cache objects in different bins.
$data = $this
->randomName(100);
$cache = new APDQCache('cache');
$cache
->set($data, $data, CACHE_TEMPORARY);
$cached = $cache
->get($data);
$this
->assertTrue(isset($cached->data) && $cached->data === $data, 'Cached item retrieved.');
$cache_page = new APDQCache('cache_page');
$cache_page
->set($data, $data, CACHE_TEMPORARY);
// Expire old items in the 'page' bin.
$cache_page
->clear();
// Since the database cache uses REQUEST_TIME, set the $_SESSION variable
// manually to force it to the current time.
$_SESSION['cache_expiration']['cache_page'] = time();
// Items in the default cache bin should not be expired.
$cached = $cache
->get($data);
$this
->assertTrue(isset($cached->data) && $cached->data == $data, 'Cached item retrieved');
// Despite the minimum cache lifetime, the item in the 'page' bin should
// be invalidated for the current user.
$cached = $cache_page
->get($data);
$this
->assertFalse($cached, 'Cached item was invalidated');
}