function PhpBackend::prepareItem

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Cache/PhpBackend.php \Drupal\Core\Cache\PhpBackend::prepareItem()
  2. 8.9.x core/lib/Drupal/Core/Cache/PhpBackend.php \Drupal\Core\Cache\PhpBackend::prepareItem()
  3. 10 core/lib/Drupal/Core/Cache/PhpBackend.php \Drupal\Core\Cache\PhpBackend::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: 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.

1 call to PhpBackend::prepareItem()
PhpBackend::getByHash in core/lib/Drupal/Core/Cache/PhpBackend.php
Fetch a cache item using a hashed cache ID.

File

core/lib/Drupal/Core/Cache/PhpBackend.php, line 132

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 >= $this->time
        ->getRequestTime();
    // 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;
}

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