Skip to content

Commit

Permalink
[Cache] Use generator in ArrayAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurimas Niekis authored and nicolas-grekas committed Jan 25, 2016
1 parent 0d3bde8 commit 367e784
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Symfony/Component/Cache/Adapter/ArrayAdapter.php
Expand Up @@ -58,16 +58,11 @@ public function getItem($key)
*/
public function getItems(array $keys = array())
{
$f = $this->createCacheItem;
$items = array();
$now = time();

foreach ($keys as $key) {
$isHit = isset($this->expiries[$this->validateKey($key)]) && ($this->expiries[$key] >= $now || !$this->deleteItem($key));
$items[$key] = $f($key, $isHit ? $this->values[$key] : null, $isHit);
$this->validateKey($key);
}

return $items;
return $this->generateItems($keys);
}

/**
Expand Down Expand Up @@ -176,4 +171,15 @@ private function validateKey($key)

return $key;
}

private function generateItems(array $keys)
{
$f = $this->createCacheItem;

foreach ($keys as $key) {
$isHit = isset($this->expiries[$key]) && ($this->expiries[$key] >= time() || !$this->deleteItem($key));

yield $key => $f($key, $isHit ? $this->values[$key] : null, $isHit);
}
}
}
Expand Up @@ -21,6 +21,7 @@ class ArrayAdapterTest extends CachePoolTest
{
protected $skippedTests = array(
'testDeferredSaveWithoutCommit' => 'Assumes a shared cache which ArrayAdapter is not.',
'testSaveWithoutExpire' => 'Assumes a shared cache which ArrayAdapter is not.',
'testDeferredExpired' => 'Failing for now, needs to be fixed.',
);

Expand Down
Expand Up @@ -22,6 +22,7 @@ class DoctrineAdapterTest extends CachePoolTest
{
protected $skippedTests = array(
'testDeferredSaveWithoutCommit' => 'Assumes a shared cache which ArrayCache is not.',
'testSaveWithoutExpire' => 'Assumes a shared cache which ArrayCache is not.',
'testDeferredExpired' => 'Failing for now, needs to be fixed.',
);

Expand Down
Expand Up @@ -22,6 +22,7 @@ class ProxyAdapterTest extends CachePoolTest
{
protected $skippedTests = array(
'testDeferredSaveWithoutCommit' => 'Assumes a shared cache which ArrayAdapter is not.',
'testSaveWithoutExpire' => 'Assumes a shared cache which ArrayAdapter is not.',
'testDeferredExpired' => 'Failing for now, needs to be fixed.',
);

Expand Down

0 comments on commit 367e784

Please sign in to comment.