7.x cache.test CacheClearCase::testMinimumCacheLifetime()

Test minimum cache lifetime.


modules/simpletest/tests/cache.test, line 370


Test cache clearing methods.


function testMinimumCacheLifetime() {

  // Set a minimum/maximum cache lifetime.

  // Login as a newly-created user.
  $account = $this

  // Set two cache objects in different bins.
  $data = $this
  cache_set($data, $data, 'cache', CACHE_TEMPORARY);
  $cached = cache_get($data);
    ->assertTrue(isset($cached->data) && $cached->data === $data, 'Cached item retrieved.');
  cache_set($data, $data, 'cache_page', CACHE_TEMPORARY);

  // Expire temporary items in the 'page' bin.
  cache_clear_all(NULL, 'cache_page');

  // 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);
    ->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_get($data, 'cache_page');
    ->assertFalse($cached, 'Cached item was invalidated');