Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 367e784

Browse files
Aurimas Niekisnicolas-grekas
Aurimas Niekis
authored andcommitted
[Cache] Use generator in ArrayAdapter
1 parent 0d3bde8 commit 367e784

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

src/Symfony/Component/Cache/Adapter/ArrayAdapter.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,11 @@ public function getItem($key)
5858
*/
5959
public function getItems(array $keys = array())
6060
{
61-
$f = $this->createCacheItem;
62-
$items = array();
63-
$now = time();
64-
6561
foreach ($keys as $key) {
66-
$isHit = isset($this->expiries[$this->validateKey($key)]) && ($this->expiries[$key] >= $now || !$this->deleteItem($key));
67-
$items[$key] = $f($key, $isHit ? $this->values[$key] : null, $isHit);
62+
$this->validateKey($key);
6863
}
6964

70-
return $items;
65+
return $this->generateItems($keys);
7166
}
7267

7368
/**
@@ -176,4 +171,15 @@ private function validateKey($key)
176171

177172
return $key;
178173
}
174+
175+
private function generateItems(array $keys)
176+
{
177+
$f = $this->createCacheItem;
178+
179+
foreach ($keys as $key) {
180+
$isHit = isset($this->expiries[$key]) && ($this->expiries[$key] >= time() || !$this->deleteItem($key));
181+
182+
yield $key => $f($key, $isHit ? $this->values[$key] : null, $isHit);
183+
}
184+
}
179185
}

src/Symfony/Component/Cache/Tests/Adapter/ArrayAdapterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class ArrayAdapterTest extends CachePoolTest
2121
{
2222
protected $skippedTests = array(
2323
'testDeferredSaveWithoutCommit' => 'Assumes a shared cache which ArrayAdapter is not.',
24+
'testSaveWithoutExpire' => 'Assumes a shared cache which ArrayAdapter is not.',
2425
'testDeferredExpired' => 'Failing for now, needs to be fixed.',
2526
);
2627

src/Symfony/Component/Cache/Tests/Adapter/DoctrineAdapterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class DoctrineAdapterTest extends CachePoolTest
2222
{
2323
protected $skippedTests = array(
2424
'testDeferredSaveWithoutCommit' => 'Assumes a shared cache which ArrayCache is not.',
25+
'testSaveWithoutExpire' => 'Assumes a shared cache which ArrayCache is not.',
2526
'testDeferredExpired' => 'Failing for now, needs to be fixed.',
2627
);
2728

src/Symfony/Component/Cache/Tests/Adapter/ProxyAdapterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ProxyAdapterTest extends CachePoolTest
2222
{
2323
protected $skippedTests = array(
2424
'testDeferredSaveWithoutCommit' => 'Assumes a shared cache which ArrayAdapter is not.',
25+
'testSaveWithoutExpire' => 'Assumes a shared cache which ArrayAdapter is not.',
2526
'testDeferredExpired' => 'Failing for now, needs to be fixed.',
2627
);
2728

0 commit comments

Comments
 (0)