You are here

protected function CacheBackendMongodb::prepareItem in MongoDB 8

Prepares a cached item.

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

Parameters

\stdClass $cache: An item loaded from get() or getMultiple().

Return value

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

1 call to CacheBackendMongodb::prepareItem()
CacheBackendMongodb::getMultiple in src/CacheBackendMongodb.php
Implements Drupal\Core\Cache\CacheBackendInterface::getMultiple().

File

src/CacheBackendMongodb.php, line 120
Definition of Drupal\mongodb/CacheBackendMongodb.

Class

CacheBackendMongodb
Defines MongoDB cache implementation.

Namespace

Drupal\mongodb

Code

protected function prepareItem($cache, $allow_invalid) {
  if (!isset($cache->data)) {
    return FALSE;
  }
  $cache->tags = $cache->tags ? explode(' ', $cache->tags) : array();

  // Check expire time.
  $cache->valid = $cache->expire instanceof \MongoDate ? $cache->expire->sec >= REQUEST_TIME : $cache->expire == CacheBackendInterface::CACHE_PERMANENT;

  // Check if invalidateTags() has been called with any of the items's tags.
  if (!$this->checksumProvider
    ->isValid($cache->checksum, $cache->tags)) {
    $cache->valid = FALSE;
  }
  if (!$allow_invalid && !$cache->valid) {
    return FALSE;
  }
  if ($cache->data instanceof \MongoBinData) {
    $cache->data = $cache->data->bin;
  }

  // Unserialize and return the cached data.
  if ($cache->serialized) {
    $cache->data = unserialize($cache->data);
  }
  return $cache;
}