You are here

protected function FileSystemBackend::prepareItem in File Cache 8

Prepares a cache item for returning to the cache handler.

Checks that items are either permanent or did not expire, and returns data as appropriate.

Parameters

object $item: A cache item.

bool $allow_invalid: (optional) If TRUE, cache items may be returned even if they have expired or been invalidated.

Return value

object|null The item with data as appropriate or NULL if there is no valid item to load.

2 calls to FileSystemBackend::prepareItem()
FileSystemBackend::garbageCollection in src/Cache/FileSystemBackend.php
Performs garbage collection on a cache bin.
FileSystemBackend::get in src/Cache/FileSystemBackend.php
Returns data from the persistent cache.

File

src/Cache/FileSystemBackend.php, line 363

Class

FileSystemBackend
A cache backend that stores cache items as files on the file system.

Namespace

Drupal\filecache\Cache

Code

protected function prepareItem(\stdClass $item, $allow_invalid) {
  if (!isset($item->data)) {
    return NULL;
  }

  // Check expire time.
  $item->valid = $item->expire == Cache::PERMANENT || $item->expire >= $this
    ->getRequestTime();

  // Check if invalidateTags() has been called with any of the item's tags.
  if (!$this->checksumProvider
    ->isValid($item->checksum, $item->tags)) {
    $item->valid = FALSE;
  }
  if (!$allow_invalid && !$item->valid) {
    return NULL;
  }
  return $item;
}