MemoryBackend::prepareItem

protected MemoryBackend::prepareItem($cache, $allow_invalid)

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

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.

File

core/lib/Drupal/Core/Cache/MemoryBackend.php, line 79

Class

MemoryBackend
Defines a memory cache implementation.

Namespace

Drupal\Core\Cache

Code

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;
}
doc_Drupal
2016-10-29 09:25:47
Comments
Leave a Comment

Please login to continue.