function DatabaseBackend::prepareItem
Same name in other branches
- 9 core/lib/Drupal/Core/Cache/DatabaseBackend.php \Drupal\Core\Cache\DatabaseBackend::prepareItem()
- 8.9.x core/lib/Drupal/Core/Cache/DatabaseBackend.php \Drupal\Core\Cache\DatabaseBackend::prepareItem()
- 10 core/lib/Drupal/Core/Cache/DatabaseBackend.php \Drupal\Core\Cache\DatabaseBackend::prepareItem()
Prepares 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 self::get() or self::getMultiple().
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()
- DatabaseBackend::getMultiple in core/
lib/ Drupal/ Core/ Cache/ DatabaseBackend.php - Returns data from the persistent cache when given an array of cache IDs.
File
-
core/
lib/ Drupal/ Core/ Cache/ DatabaseBackend.php, line 164
Class
- DatabaseBackend
- Defines a default cache implementation.
Namespace
Drupal\Core\CacheCode
protected function prepareItem($cache, $allow_invalid) {
if (!isset($cache->data)) {
return FALSE;
}
$cache->tags = $cache->tags ? explode(' ', $cache->tags) : [];
// Check expire time.
$cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= $this->time
->getRequestTime();
// Check if invalidateTags() has been called with any of the item's tags.
if (!$this->checksumProvider
->isValid($cache->checksum, $cache->tags)) {
$cache->valid = FALSE;
}
if (!$allow_invalid && !$cache->valid) {
return FALSE;
}
// Unserialize and return the cached data.
if ($cache->serialized) {
$cache->data = $this->serializer
->decode($cache->data);
}
return $cache;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.