function MemoryCache::prepareItem

Same name in other branches
  1. 9 core/lib/Drupal/Core/Cache/MemoryCache/MemoryCache.php \Drupal\Core\Cache\MemoryCache\MemoryCache::prepareItem()
  2. 8.9.x core/lib/Drupal/Core/Cache/MemoryCache/MemoryCache.php \Drupal\Core\Cache\MemoryCache\MemoryCache::prepareItem()
  3. 11.x core/lib/Drupal/Core/Cache/MemoryCache/MemoryCache.php \Drupal\Core\Cache\MemoryCache\MemoryCache::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. Defaults to FALSE.

Return value

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

Overrides MemoryBackend::prepareItem

File

core/lib/Drupal/Core/Cache/MemoryCache/MemoryCache.php, line 33

Class

MemoryCache
Defines a memory cache implementation.

Namespace

Drupal\Core\Cache\MemoryCache

Code

protected function prepareItem($cache, $allow_invalid = FALSE) {
    if (!isset($cache->data)) {
        return FALSE;
    }
    // Check expire time.
    $cache->valid = $cache->expire == static::CACHE_PERMANENT || $cache->expire >= $this->time
        ->getRequestTime();
    if (!$allow_invalid && !$cache->valid) {
        return FALSE;
    }
    return $cache;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.