You are here

public function CacheBackendWrapper::get in Devel 8.3

Same name and namespace in other branches
  1. 8 webprofiler/src/Cache/CacheBackendWrapper.php \Drupal\webprofiler\Cache\CacheBackendWrapper::get()
  2. 8.2 webprofiler/src/Cache/CacheBackendWrapper.php \Drupal\webprofiler\Cache\CacheBackendWrapper::get()
  3. 4.x webprofiler/src/Cache/CacheBackendWrapper.php \Drupal\webprofiler\Cache\CacheBackendWrapper::get()

Returns data from the persistent cache.

Parameters

string $cid: The cache ID of the data to retrieve.

bool $allow_invalid: (optional) If TRUE, a cache item may be returned even if it is expired or has been invalidated. Such items may sometimes be preferred, if the alternative is recalculating the value stored in the cache, especially if another concurrent request is already recalculating the same value. The "valid" property of the returned object indicates whether the item is valid or not. Defaults to FALSE.

Return value

object|false The cache item or FALSE on failure.

Overrides CacheBackendInterface::get

See also

\Drupal\Core\Cache\CacheBackendInterface::getMultiple()

File

webprofiler/src/Cache/CacheBackendWrapper.php, line 55

Class

CacheBackendWrapper
Wraps an existing cache backend to track calls to the cache backend.

Namespace

Drupal\webprofiler\Cache

Code

public function get($cid, $allow_invalid = FALSE) {
  $cache = $this->cacheBackend
    ->get($cid, $allow_invalid);
  if ($cache) {
    $cacheCopy = new \stdClass();
    $cacheCopy->cid = $cache->cid;
    $cacheCopy->expire = $cache->expire;
    $cacheCopy->tags = $cache->tags;
    $this->cacheDataCollector
      ->registerCacheHit($this->bin, $cacheCopy);
  }
  else {
    $this->cacheDataCollector
      ->registerCacheMiss($this->bin, $cid);
  }
  return $cache;
}