Commit 687433da authored by catch's avatar catch

Issue #1281484 by Berdir: wildcards clears broken on subsequent requests.

parent a0b7cb6e
......@@ -129,7 +129,7 @@ function dmemcache_get_multi($keys, $bin = 'cache', $mc = NULL) {
foreach ($keys as $key => $cid) {
$full_key = dmemcache_key($cid, $bin);
$statistics[$full_key] = array('getMulti', $bin, $full_key);
$full_keys[] = $full_key;
$full_keys[$cid] = $full_key;
}
$results = array();
if ($mc || ($mc = dmemcache_object($bin))) {
......@@ -161,10 +161,9 @@ function dmemcache_get_multi($keys, $bin = 'cache', $mc = NULL) {
// Convert the full keys back to the cid.
$cid_results = array();
foreach ($results as $value) {
if (is_object($value)) {
$cid_results[$value->cid] = $value;
}
$cid_lookup = array_flip($full_keys);
foreach ($results as $key => $value) {
$cid_results[$cid_lookup[$key]] = $value;
}
return $cid_results;
}
......
......@@ -257,12 +257,11 @@ class MemCacheDrupal implements DrupalCacheInterface {
foreach ($this->wildcard_flushes[$this->bin] as $flush_length => $timestamp) {
if ($length >= $flush_length && $timestamp >= ($_SERVER['REQUEST_TIME'] - $this->invalidate)) {
$key = '.wildcard-' . substr($cid, 0, $flush_length);
$wildcard = dmemcache_key($key, $this->bin);
if (isset($wildcards[$this->bin][$wildcard])) {
$matching[$wildcard] = $wildcards[$this->bin][$wildcard];
if (isset($wildcards[$this->bin][$key])) {
$matching[$key] = $wildcards[$this->bin][$key];
}
else {
$lookup[$wildcard] = $key;
$lookup[$key] = $key;
}
}
}
......@@ -285,11 +284,12 @@ class MemCacheDrupal implements DrupalCacheInterface {
// Also store failed lookups in our static cache, so we don't have to
// do repeat lookups on single page loads.
foreach ($lookup as $wildcard => $key) {
$wildcards[$this->bin][$wildcard] = 0;
foreach ($lookup as $key => $key) {
$wildcards[$this->bin][$key] = 0;
}
}
}
if ($flush) {
// Avoid too many calls to variable_set() by only recording a flush for
// a fraction of the wildcard invalidation variable, per cid length.
......@@ -301,14 +301,13 @@ class MemCacheDrupal implements DrupalCacheInterface {
$this->wildcard_flushes[$this->bin][$length] = $_SERVER['REQUEST_TIME'];
variable_set('memcache_wildcard_flushes', $this->wildcard_flushes);
}
$wildcard = dmemcache_key('.wildcard-' . $cid, $this->bin);
if (isset($wildcards[$this->bin][$wildcard]) && $wildcards[$this->bin][$wildcard] != 0) {
$this->memcache->increment($wildcard);
$wildcards[$this->bin][$wildcard]++;
$key = '.wildcard-' . $cid;
if (isset($wildcards[$this->bin][$key]) && $wildcards[$this->bin][$key] != 0) {
$this->memcache->increment($key);
$wildcards[$this->bin][$key]++;
}
else {
$wildcards[$this->bin][$wildcard] = 1;
dmemcache_set('.wildcard-' . $cid, '1', 0, $this->bin);
dmemcache_set($key, '1', 0, $this->bin);
}
}
return $matching;
......
......@@ -363,27 +363,27 @@ class MemCacheClearCase extends MemcacheTestCase {
*/
function clearWildcardPrefixTest() {
$this->resetVariables();
cache_set('test_cid_clear1', $this->default_value, $this->default_bin);
cache_set('test_cid_clear2', $this->default_value, $this->default_bin);
$this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value)
&& $this->checkCacheExists('test_cid_clear2', $this->default_value),
cache_set('test_cid_clear:1', $this->default_value, $this->default_bin);
cache_set('test_cid_clear:2', $this->default_value, $this->default_bin);
$this->assertTrue($this->checkCacheExists('test_cid_clear:1', $this->default_value)
&& $this->checkCacheExists('test_cid_clear:2', $this->default_value),
t('Two caches were created for checking cid substring with wildcard true.'));
cache_clear_all('test_', $this->default_bin, TRUE);
$this->assertFalse($this->checkCacheExists('test_cid_clear1', $this->default_value)
|| $this->checkCacheExists('test_cid_clear2', $this->default_value),
cache_clear_all('test_cid_clear:', $this->default_bin, TRUE);
$this->assertFalse($this->checkCacheExists('test_cid_clear:1', $this->default_value)
|| $this->checkCacheExists('test_cid_clear:2', $this->default_value),
t('Two caches removed after clearing cid substring with wildcard true.'));
// Test for the case where a wildcard object disappears, for example a
// partial memcache restart or eviction.
cache_set('test_cid_clear1', $this->default_value, $this->default_bin);
$this->assertTrue($this->checkCacheExists('test_cid_clear1', $this->default_value), 'The cache was created successfully.');
cache_set('test_cid_clear:1', $this->default_value, $this->default_bin);
$this->assertTrue($this->checkCacheExists('test_cid_clear:1', $this->default_value), 'The cache was created successfully.');
cache_clear_all('test_', $this->default_bin, TRUE);
$this->assertFalse($this->checkCacheExists('test_cid_clear1', $this->default_value), 'The cache was cleared successfully.');
$this->assertFalse($this->checkCacheExists('test_cid_clear:1', $this->default_value), 'The cache was cleared successfully.');
// Delete the wildcard manually to simulate an eviction.
$wildcard = '.wildcard-' . 'test_';
$wildcard = '.wildcard-' . 'test_cid_clear:';
dmemcache_delete($wildcard, $this->default_bin);
// Reset the memcache_wildcards() static cache.
// @todo: this is a class object in D7.
//memcache_wildcards(FALSE, FALSE, FALSE, TRUE);
$this->assertFalse($this->checkCacheExists('test_cid_clear1', $this->default_value), 'The cache was cleared successfully.');
$this->assertFalse($this->checkCacheExists('test_cid_clear:1', $this->default_value), 'The cache was cleared successfully.');
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment