You are here

protected function Cache::prepareItem in MongoDB 7

Prepare a cached item.

Checks that items are either permanent not yet expired, and unserializes data as appropriate.

Parameters

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

Return value

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

2 calls to Cache::prepareItem()
Cache::get in mongodb_cache/mongodb_cache_plugin.php
Cache::getMultiple in mongodb_cache/mongodb_cache_plugin.php

File

mongodb_cache/mongodb_cache_plugin.php, line 280

Class

Cache
MongoDB cache implementation.

Namespace

Drupal\mongodb_cache

Code

protected function prepareItem($cache) {
  if (!$cache || !isset($cache['data'])) {
    return FALSE;
  }
  unset($cache['_id']);
  $cache = (object) $cache;

  // 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) && isset($_SESSION['cache_expiration'][$this->bin]) && $_SESSION['cache_expiration'][$this->bin] > $cache->created) {

    // These cached data are too old and thus not valid for us, ignore it.
    return FALSE;
  }
  if ($cache->data instanceof \MongoBinData) {
    $cache->data = $cache->data->bin;
  }
  if ($cache->serialized) {
    $cache->data = unserialize($cache->data);
  }
  return $cache;
}