protected function DatabaseBackend::prepareItem

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 cache_get() or cache_get_multiple().

bool $allow_invalid: If FALSE, the method returns FALSE if the cache item is not valid.

Return value

mixed|false The item with data unserialized as appropriate and a property indicating whether the item is valid, or FALSE if there is no valid item to load.

1 call to DatabaseBackend::prepareItem()

File

drupal/core/lib/Drupal/Core/Cache/DatabaseBackend.php, line 106
Definition of Drupal\Core\Cache\DatabaseBackend.

Class

DatabaseBackend
Defines a default cache implementation.

Namespace

Drupal\Core\Cache

Code

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

  // Check if deleteTags() has been called with any of the entry's tags.
  if ($cache->checksum_deletions != $checksum['deletions']) {
    return FALSE;
  }

  // Check expire time.
  $cache->valid = $cache->expire == CacheBackendInterface::CACHE_PERMANENT || $cache->expire >= REQUEST_TIME;

  // Check if invalidateTags() has been called with any of the entry's tags.
  if ($cache->checksum_invalidations != $checksum['invalidations']) {
    $cache->valid = FALSE;
  }
  if (!$allow_invalid && !$cache->valid) {
    return FALSE;
  }

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