protected function DrupalDatabaseCache::prepareItem

protected DrupalDatabaseCache::prepareItem($cache)

Prepares a cached item.

Checks that items are either permanent or did not expire, and unserializes data as appropriate.

Parameters

$cache: An item loaded from cache_get() or cache_get_multiple().

Return value

The item with data unserialized as appropriate or FALSE if there is no valid item to load.

File

includes/cache.inc, line 422
Functions and interfaces for cache handling.

Class

DrupalDatabaseCache
Defines a default cache implementation.

Code

protected function prepareItem($cache) {
  global $user;

  if (!isset($cache->data)) {
    return FALSE;
  }
  // If the cached data is temporary and subject to a per-user minimum
  // lifetime, compare the cache entry timestamp with the user session
  // cache_expiration timestamp. If the cache entry is too old, ignore it.
  if ($cache->expire != CACHE_PERMANENT && variable_get('cache_lifetime', 0) && isset($_SESSION['cache_expiration'][$this->bin]) && $_SESSION['cache_expiration'][$this->bin] > $cache->created) {
    // Ignore cache data that is too old and thus not valid for this user.
    return FALSE;
  }

  // If the data is permanent or not subject to a minimum cache lifetime,
  // unserialize and return the cached data.
  if ($cache->serialized) {
    $cache->data = unserialize($cache->data);
  }

  return $cache;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!cache.inc/function/DrupalDatabaseCache::prepareItem/7.x