protected function ApcuBackend::prepareItem

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

Prepares a cached item.

Checks that the item is either permanent or did not expire.

Parameters

\stdClass $cache: An item loaded from cache_get() or cache_get_multiple().

bool $allow_invalid: If TRUE, a cache item may be returned even if it is expired or has been invalidated. See ::get().

Return value

mixed The cache item or FALSE if the item expired.

File

core/lib/Drupal/Core/Cache/ApcuBackend.php, line 138

Class

ApcuBackend
Stores cache items in the Alternative PHP Cache User Cache (APCu).

Namespace

Drupal\Core\Cache

Code

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

  $cache->tags = $cache->tags ? explode(' ', $cache->tags) : array();

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

  // Check if invalidateTags() has been called with any of the entry'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!ApcuBackend.php/function/ApcuBackend::prepareItem/8.1.x