bug #23065 [Cache] Fallback to positional when keyed results are broken (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 https://github.com/krakjoe/apcu/issues/247 ~~and https://github.com/facebook/hhvm/issues/7867~~
Commits
-------
28aaa8eb05
[Cache] Fallback to positional when keyed results are broken
This commit is contained in:
commit
58f03a734f
@ -266,6 +266,9 @@ abstract class AbstractAdapter implements AdapterInterface, LoggerAwareInterface
|
||||
|
||||
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 @@ abstract class AbstractCache implements CacheInterface, LoggerAwareInterface
|
||||
{
|
||||
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\FilesystemAdapter;
|
||||
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 @@ use Cache\IntegrationTests\SimpleCacheTest;
|
||||
|
||||
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__])) {
|
||||
|
Reference in New Issue
Block a user