Skip to content

Commit

Permalink
feature #18867 [Cache] Drop counting hit/miss in ProxyAdapter (nicola…
Browse files Browse the repository at this point in the history
…s-grekas)

This PR was merged into the 3.1 branch.

Discussion
----------

[Cache] Drop counting hit/miss in ProxyAdapter

| Q             | A
| ------------- | ---
| Branch?       | 3.1
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | no
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

We have no use case for these methods yet. Let's drop them and save some BC constraints.

Commits
-------

9461750 [Cache] Drop counting hit/miss in ProxyAdapter
  • Loading branch information
fabpot committed May 25, 2016
2 parents 7dc1491 + 9461750 commit 4974a8b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 51 deletions.
36 changes: 2 additions & 34 deletions src/Symfony/Component/Cache/Adapter/ProxyAdapter.php
Expand Up @@ -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)
{
Expand Down Expand Up @@ -54,13 +52,8 @@ public function getItem($key)
{
$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());
}

/**
Expand Down Expand Up @@ -158,39 +151,14 @@ private function generateItems($items)
$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);
Expand Down
17 changes: 0 additions & 17 deletions src/Symfony/Component/Cache/Tests/Adapter/ProxyAdapterTest.php
Expand Up @@ -29,21 +29,4 @@ public function createCachePool()
{
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());
}
}

0 comments on commit 4974a8b

Please sign in to comment.