CacheBackendWrapper.php in Devel 4.x
File
webprofiler/src/Cache/CacheBackendWrapper.php
View source
<?php
namespace Drupal\webprofiler\Cache;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
use Drupal\webprofiler\DataCollector\CacheDataCollector;
class CacheBackendWrapper implements CacheBackendInterface, CacheTagsInvalidatorInterface {
protected $cacheDataCollector;
protected $cacheBackend;
protected $bin;
public function __construct(CacheDataCollector $cacheDataCollector, CacheBackendInterface $cacheBackend, $bin) {
$this->cacheDataCollector = $cacheDataCollector;
$this->cacheBackend = $cacheBackend;
$this->bin = $bin;
}
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;
}
public function getMultiple(&$cids, $allow_invalid = FALSE) {
$cidsCopy = $cids;
$cache = $this->cacheBackend
->getMultiple($cids, $allow_invalid);
foreach ($cidsCopy as $cid) {
if (in_array($cid, $cids)) {
$this->cacheDataCollector
->registerCacheMiss($this->bin, $cid);
}
else {
$cacheCopy = new \stdClass();
$cacheCopy->cid = $cache[$cid]->cid;
$cacheCopy->expire = $cache[$cid]->expire;
$cacheCopy->tags = $cache[$cid]->tags;
$this->cacheDataCollector
->registerCacheHit($this->bin, $cacheCopy);
}
}
return $cache;
}
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = []) {
return $this->cacheBackend
->set($cid, $data, $expire, $tags);
}
public function setMultiple(array $items) {
return $this->cacheBackend
->setMultiple($items);
}
public function delete($cid) {
return $this->cacheBackend
->delete($cid);
}
public function deleteMultiple(array $cids) {
return $this->cacheBackend
->deleteMultiple($cids);
}
public function deleteAll() {
return $this->cacheBackend
->deleteAll();
}
public function invalidate($cid) {
return $this->cacheBackend
->invalidate($cid);
}
public function invalidateMultiple(array $cids) {
return $this->cacheBackend
->invalidateMultiple($cids);
}
public function invalidateTags(array $tags) {
if ($this->cacheBackend instanceof CacheTagsInvalidatorInterface) {
$this->cacheBackend
->invalidateTags($tags);
}
}
public function invalidateAll() {
return $this->cacheBackend
->invalidateAll();
}
public function garbageCollection() {
return $this->cacheBackend
->garbageCollection();
}
public function removeBin() {
return $this->cacheBackend
->removeBin();
}
}