function MemoryBackend::prepareItem
Same name in other branches
- 9 core/lib/Drupal/Core/Cache/MemoryBackend.php \Drupal\Core\Cache\MemoryBackend::prepareItem()
- 10 core/lib/Drupal/Core/Cache/MemoryBackend.php \Drupal\Core\Cache\MemoryBackend::prepareItem()
- 11.x core/lib/Drupal/Core/Cache/MemoryBackend.php \Drupal\Core\Cache\MemoryBackend::prepareItem()
Prepares a cached item.
Checks that items are either permanent or did not expire, and returns data as appropriate.
Parameters
object $cache: An item loaded from self::get() or self::getMultiple().
bool $allow_invalid: (optional) If TRUE, cache items may be returned even if they have expired or been invalidated.
Return value
mixed The item with data as appropriate or FALSE if there is no valid item to load.
2 calls to MemoryBackend::prepareItem()
- MemoryBackend::get in core/
lib/ Drupal/ Core/ Cache/ MemoryBackend.php - Returns data from the persistent cache.
- MemoryBackend::getMultiple in core/
lib/ Drupal/ Core/ Cache/ MemoryBackend.php - Returns data from the persistent cache when given an array of cache IDs.
1 method overrides MemoryBackend::prepareItem()
- MemoryCache::prepareItem in core/
lib/ Drupal/ Core/ Cache/ MemoryCache/ MemoryCache.php - Prepares a cached item.
File
-
core/
lib/ Drupal/ Core/ Cache/ MemoryBackend.php, line 77
Class
- MemoryBackend
- Defines a memory cache implementation.
Namespace
Drupal\Core\CacheCode
protected function prepareItem($cache, $allow_invalid) {
if (!isset($cache->data)) {
return FALSE;
}
// The object passed into this function is the one stored in $this->cache.
// We must clone it as part of the preparation step so that the actual
// cache object is not affected by the unserialize() call or other
// manipulations of the returned object.
$prepared = clone $cache;
$prepared->data = unserialize($prepared->data);
// Check expire time.
$prepared->valid = $prepared->expire == Cache::PERMANENT || $prepared->expire >= $this->getRequestTime();
if (!$allow_invalid && !$prepared->valid) {
return FALSE;
}
return $prepared;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.