[Cache] Drop counting hit/miss in ProxyAdapter
This commit is contained in:
parent
7dc1491ec0
commit
9461750bd0
@ -24,8 +24,6 @@ class ProxyAdapter implements AdapterInterface
|
||||
private $namespace;
|
||||
private $namespaceLen;
|
||||
private $createCacheItem;
|
||||
private $hits = 0;
|
||||
private $misses = 0;
|
||||
|
||||
public function __construct(CacheItemPoolInterface $pool, $namespace = '', $defaultLifetime = 0)
|
||||
{
|
||||
@ -54,13 +52,8 @@ class ProxyAdapter implements AdapterInterface
|
||||
{
|
||||
$f = $this->createCacheItem;
|
||||
$item = $this->pool->getItem($this->getId($key));
|
||||
if ($isHit = $item->isHit()) {
|
||||
++$this->hits;
|
||||
} else {
|
||||
++$this->misses;
|
||||
}
|
||||
|
||||
return $f($key, $item->get(), $isHit);
|
||||
return $f($key, $item->get(), $item->isHit());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -158,39 +151,14 @@ class ProxyAdapter implements AdapterInterface
|
||||
$f = $this->createCacheItem;
|
||||
|
||||
foreach ($items as $key => $item) {
|
||||
if ($isHit = $item->isHit()) {
|
||||
++$this->hits;
|
||||
} else {
|
||||
++$this->misses;
|
||||
}
|
||||
if ($this->namespaceLen) {
|
||||
$key = substr($key, $this->namespaceLen);
|
||||
}
|
||||
|
||||
yield $key => $f($key, $item->get(), $isHit);
|
||||
yield $key => $f($key, $item->get(), $item->isHit());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of cache read hits.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getHits()
|
||||
{
|
||||
return $this->hits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of cache read misses.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getMisses()
|
||||
{
|
||||
return $this->misses;
|
||||
}
|
||||
|
||||
private function getId($key)
|
||||
{
|
||||
CacheItem::validateKey($key);
|
||||
|
@ -29,21 +29,4 @@ class ProxyAdapterTest extends CachePoolTest
|
||||
{
|
||||
return new ProxyAdapter(new ArrayAdapter());
|
||||
}
|
||||
|
||||
public function testGetHitsMisses()
|
||||
{
|
||||
$pool = $this->createCachePool();
|
||||
|
||||
$this->assertSame(0, $pool->getHits());
|
||||
$this->assertSame(0, $pool->getMisses());
|
||||
|
||||
$bar = $pool->getItem('bar');
|
||||
$this->assertSame(0, $pool->getHits());
|
||||
$this->assertSame(1, $pool->getMisses());
|
||||
|
||||
$pool->save($bar->set('baz'));
|
||||
$bar = $pool->getItem('bar');
|
||||
$this->assertSame(1, $pool->getHits());
|
||||
$this->assertSame(1, $pool->getMisses());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user