You are here

protected function FieldEncryptDatabaseCache::prepareItem in Field Encryption 7

Prepare a cached item.

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

Parameters

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

Return value

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

Overrides DrupalDatabaseCache::prepareItem

File

./field_encrypt.cache.inc, line 68
Field encryption cache classes.

Class

FieldEncryptDatabaseCache
Class FieldEncryptDatabaseCache.

Code

protected function prepareItem($cache) {
  global $user;
  if (!isset($cache->data)) {
    return FALSE;
  }

  // If enforcing a minimum cache lifetime, validate that the data is
  // currently valid for this user before we return it by making sure the
  // cache entry was created before the timestamp in the current session's
  // cache timer. The cache variable is loaded into the $user object by
  // _drupal_session_read() in session.inc. If the data is permanent or we're
  // not enforcing a minimum cache lifetime always return the cached data.
  if ($cache->expire != CACHE_PERMANENT && variable_get('cache_lifetime', 0) && $user->cache > $cache->created) {

    // This cache data is too old and thus not valid for us, ignore it.
    return FALSE;
  }
  try {
    $cache->data = $this
      ->decrypt($cache->data);
  } catch (Exception $e) {
    watchdog_exception('field_encrypt', $e);
    return FALSE;
  }
  if ($cache->serialized) {
    $cache->data = unserialize($cache->data);
  }
  return $cache;
}