You are here

protected function MobileToolsDatabaseCache::prepareItem in Mobile Tools 7.3

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 MobileToolsDatabaseCache::prepareItem()
MobileToolsDatabaseCache::getMultiple in mobile_tools_cache/mobile_tools_cache.module
Implements DrupalCacheInterface::getMultiple().

File

mobile_tools_cache/mobile_tools_cache.module, line 138
Main module for mobile_tools_cache

Class

MobileToolsDatabaseCache
Implements DrupalCacheInterface

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