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

Skip to content

Commit 28aaa8e

Browse files
[Cache] Fallback to positional when keyed results are broken
1 parent c973e8a commit 28aaa8e

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ private function generateItems($items, &$keys)
266266

267267
try {
268268
foreach ($items as $id => $value) {
269+
if (!isset($keys[$id])) {
270+
$id = key($keys);
271+
}
269272
$key = $keys[$id];
270273
unset($keys[$id]);
271274
yield $key => $f($key, $value, true);

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ class MemcachedAdapter extends AbstractAdapter
1919

2020
protected $maxIdLength = 250;
2121

22+
/**
23+
* Constructor.
24+
*
25+
* Using a MemcachedAdapter with a TagAwareAdapter for storing tags is discouraged.
26+
* Using a RedisAdapter is recommended instead. If you cannot do otherwise, be aware that:
27+
* - the Memcached::OPT_BINARY_PROTOCOL must be enabled
28+
* (that's the default when using MemcachedAdapter::createConnection());
29+
* - tags eviction by Memcached's LRU algorithm will break by-tags invalidation;
30+
* your Memcached memory should be large enough to never trigger LRU.
31+
*
32+
* Using a MemcachedAdapter as a pure items store is fine.
33+
*/
2234
public function __construct(\Memcached $client, $namespace = '', $defaultLifetime = 0)
2335
{
2436
$this->init($client, $namespace, $defaultLifetime);

src/Symfony/Component/Cache/Simple/AbstractCache.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ private function generateValues($values, &$keys, $default)
162162
{
163163
try {
164164
foreach ($values as $id => $value) {
165+
if (!isset($keys[$id])) {
166+
$id = key($keys);
167+
}
165168
$key = $keys[$id];
166169
unset($keys[$id]);
167170
yield $key => $value;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
1616
use Symfony\Component\Cache\Adapter\TraceableTagAwareAdapter;
1717

18+
/**
19+
* @group time-sensitive
20+
*/
1821
class TraceableTagAwareAdapterTest extends TraceableAdapterTest
1922
{
2023
public function testInvalidateTags()

src/Symfony/Component/Cache/Tests/Simple/CacheTestCase.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515

1616
abstract class CacheTestCase extends SimpleCacheTest
1717
{
18+
public static function validKeys()
19+
{
20+
if (defined('HHVM_VERSION')) {
21+
return parent::validKeys();
22+
}
23+
24+
return array_merge(parent::validKeys(), array(array("a\0b")));
25+
}
26+
1827
public function testDefaultLifeTime()
1928
{
2029
if (isset($this->skippedTests[__FUNCTION__])) {

0 commit comments

Comments
 (0)