Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Cache] Drop counting hit/miss in ProxyAdapter #18867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Cache] Drop counting hit/miss in ProxyAdapter
  • Loading branch information
nicolas-grekas committed May 25, 2016
commit 9461750bd0703a01a31c3cdcebf922cda404d14d
36 changes: 2 additions & 34 deletions 36 src/Symfony/Component/Cache/Adapter/ProxyAdapter.php
Original file line number Diff line number Diff line change
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 17 src/Symfony/Component/Cache/Tests/Adapter/ProxyAdapterTest.php
Original file line number Diff line number Diff line change
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());
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.