10000 [Cache] Fallback to positional when keyed results are broken by nicolas-grekas · Pull Request #23065 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Cache] Fallback to positional when keyed results are broken #23065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Cache/Simple/AbstractCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/Cache/Tests/Simple/CacheTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__])) {
Expand Down
0