function DrupalDatabaseCache::prepareItem

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.

1 call to DrupalDatabaseCache::prepareItem()
DrupalDatabaseCache::getMultiple in includes/cache.inc
Implements DrupalCacheInterface::getMultiple().

File

includes/cache.inc, line 432

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.