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

Commit 48d91a8

Browse filesBrowse files
committed
feature #17522 [Cache] Use generator in ArrayAdapter (gcds)
This PR was merged into the 3.1-dev branch. Discussion ---------- [Cache] Use generator in ArrayAdapter | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17435 | License | MIT | Doc PR | - Commits ------- 367e784 [Cache] Use generator in ArrayAdapter
2 parents acfa9ab + 367e784 commit 48d91a8
Copy full SHA for 48d91a8

File tree

4 files changed

+16
-7
lines changed
Filter options

4 files changed

+16
-7
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/ArrayAdapter.php
+13-7Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Adapter/ArrayAdapterTest.php
+1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Adapter/DoctrineAdapterTest.php
+1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Tests/Adapter/ProxyAdapterTest.php
+1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.