[Cache] Fallback to positional when keyed results are broken

This commit is contained in:
Nicolas Grekas 2017-06-05 10:23:13 +02:00
parent c973e8ad00
commit 28aaa8eb05
5 changed files with 30 additions and 0 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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()

View File

@ -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__])) {