protected function 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;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Cache!MemoryBackend.php/function/MemoryBackend::prepareItem/8.1.x