protected function PhpBackend::prepareItem

protected PhpBackend::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: If FALSE, the method returns FALSE if the cache item is not valid.

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/PhpBackend.php, line 122

Class

PhpBackend
Defines a PHP cache implementation.

Namespace

Drupal\Core\Cache

Code

protected function prepareItem($cache, $allow_invalid) {
  if (!isset($cache->data)) {
    return FALSE;
  }

  // Check expire time.
  $cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= REQUEST_TIME;

  // 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;
  }

  return $cache;
}

© 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!PhpBackend.php/function/PhpBackend::prepareItem/8.1.x