Permalink
Browse files

bug #23065 [Cache] Fallback to positional when keyed results are brok…

…en (nicolas-grekas)

This PR was merged into the 3.3 branch.

Discussion
----------

[Cache] Fallback to positional when keyed results are broken

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Works around krakjoe/apcu#247 ~~and facebook/hhvm#7867

Commits
-------

28aaa8e [Cache] Fallback to positional when keyed results are broken
  • Loading branch information...
fabpot committed Jun 5, 2017
2 parents 1272d2a + 28aaa8e commit 58f03a734f01a2b78305bbef9258c856d237094f
@@ -266,6 +266,9 @@ private function generateItems($items, &$keys)
try {
foreach ($items as $id => $value) {
if (!isset($keys[$id])) {
$id = key($keys);
}
$key = $keys[$id];
unset($keys[$id]);
yield $key => $f($key, $value, true);
@@ -19,6 +19,18 @@ class MemcachedAdapter extends AbstractAdapter
protected $maxIdLength = 250;
/**
* Constructor.
*
* Using a MemcachedAdapter with a TagAwareAdapter for storing tags is discouraged.
* Using a RedisAdapter is recommended instead. If you cannot do otherwise, be aware that:
* - the Memcached::OPT_BINARY_PROTOCOL must be enabled
* (that's the default when using MemcachedAdapter::createConnection());
* - tags eviction by Memcached's LRU algorithm will break by-tags invalidation;
* your Memcached memory should be large enough to never trigger LRU.
*
* Using a MemcachedAdapter as a pure items store is fine.
*/
public function __construct(\Memcached $client, $namespace = '', $defaultLifetime = 0)
{
$this->init($client, $namespace, $defaultLifetime);
@@ -162,6 +162,9 @@ private function generateValues($values, &$keys, $default)
{
try {
foreach ($values as $id => $value) {
if (!isset($keys[$id])) {
$id = key($keys);
}
$key = $keys[$id];
unset($keys[$id]);
yield $key => $value;
@@ -15,6 +15,9 @@
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
use Symfony\Component\Cache\Adapter\TraceableTagAwareAdapter;
/**
* @group time-sensitive
*/
class TraceableTagAwareAdapterTest extends TraceableAdapterTest
{
public function testInvalidateTags()
@@ -15,6 +15,15 @@
abstract class CacheTestCase extends SimpleCacheTest
{
public static function validKeys()
{
if (defined('HHVM_VERSION')) {
return parent::validKeys();
}
return array_merge(parent::validKeys(), array(array("a\0b")));
}
public function testDefaultLifeTime()
{
if (isset($this->skippedTests[__FUNCTION__])) {

0 comments on commit 58f03a7

Please sign in to comment.