Cache entries seem to stay in the cache despite being cleared with cache_clear_all with wildcard enabled.

Using regular Drupal caching cache clear as expected.

Reproducable with this code (I used hook_page_alter):

  cache_clear_all('mystr_static', 'cache');
  cache_clear_all('mystr', 'cache', TRUE);
  
  $vars = array('mystr_perm', 'mystr_temp', 'mystr_time', 'mystr_static');
  foreach ($vars as $key) {
    $var = cache_get($key);
    if ($var && $var->data) {
      drupal_set_message($var->data);
    }
  }

  cache_set('mystr_perm', 'permanent - this should not be visible', 'cache', CACHE_PERMANENT);
  cache_set('mystr_temp', 'temporary - this should not be visible', 'cache', CACHE_TEMPORARY);
  cache_set('mystr_time', 'time - this should not be visible', 'cache', time() + 1000);
  cache_set('mystr_static', 'static - this should not be visible', 'cache', time() + 1000);

All texts should NOT be visible, however with the current version(s) only the exactly flushed key (mystr_static) is cleared. Do note that this required loading the page twice.

Comments

rbrandon’s picture

I am seeing the same behavior. When DB caching is turned on then:

cache_clear_all('mystr', 'my_cache_bin', TRUE);

Will delete all items prefixed with mystr. However with "my_cache_bin" using memcached the wildcard cache clear leaves the stale data in place.

timtrinidad’s picture

I'm not sure if this is the same issue - we're using memcache.inc with cache_backport on D6. I figured I'd post it in case someone else stumbles across the same issue with the same setup.

  • variable_init calls cache_get('variables', 'cache')
  • cache_get calls _cache_get_object which instantiates the MemCacheDrupal with $bin = 'cache'
  • The constructor for MemCacheDrupal calls reloadVariables
  • reloadVariables calls variable_get('memcache_wildcard_flushes', array()) which hasn't yet completed initialization (with variable_init)

This would case a statically stored MemCacheDrupal object for the 'cache' bin with no loaded memcache_wildcard_flushes values. Other bins seemed not to have been affected.

Our solution for now was to move all the cache_{set,get,clear_all}('variables') calls to its own cache_variables bin so that the 'cache' object wouldn't be instantiated incorrectly.

markpavlitski’s picture

Status: Active » Needs review
StatusFileSize
new2.11 KB

This may be caused by these issue:
https://bugs.php.net/bug.php?id=58651
https://bugzilla.redhat.com/show_bug.cgi?id=638892

MemCacheDrupal::wildcards() sets an integer value directly, which is what triggers the issues above on PECL memcache versions prior to 3.0.5.

The attached patch works around the issue by disabling compression for the PECL memcache library if the value sent to memcached is numeric.

A test case is included.

hefox’s picture

To verify that one is experiencing this bug, run this

$  drush php-eval "cache_set('test_cid:one:yep', 'test value');"
$ drush php-eval "print_r(cache_get('test_cid:one:yep'));"
stdClass Object
(
    [cid] => test_cid:one:yep
    [data] => test value
    [created] => 1382480257
    [flushes] => 0
    [expire] => 0
)
$ drush php-eval "cache_clear_all('test_cid', 'cache', TRUE); print_r(cache_get('test_cid:one:yep'));"
$ drush php-eval "print_r(cache_get('test_cid:one:yep'));"

If the last line prints the stdClass like the second line, you're experiencing this issue. Add the patch and the last line should have no results.

markpavlitski’s picture

Issue tags: +needs backport to 6.x

Needs backport.

jeremy’s picture

Issue summary: View changes
Status: Needs review » Needs work

IMO I'd rather just document that 3.0.5+ is required versus working around this (and possibly update the requirements hook to throw a warning when using an unsupported version). Anything we can do to simplify already complex code seems like a step in the right direction.

markpavlitski’s picture

StatusFileSize
new2.28 KB

It's implicitly documented in the README that there may be issues with older versions of the PECL libraries, so we could just close the ticket.

Otherwise the attached patch makes it more obvious and adds a requirements check for Memcache 3.0.6+ and Memcached 2.0.1+ as per the README recommendation.

markpavlitski’s picture

Status: Needs work » Needs review
jeremy’s picture

Status: Needs review » Fixed

Thanks, committed:
http://drupalcode.org/project/memcache.git/commitdiff/92483f6

I also included the test, perhaps someday a 2.2.x release will fix this bug at which point we'd want to support it (2.2.7 does not).

jeremy’s picture

I updated this to also trigger an error when the memcache module is enabled:
http://drupalcode.org/project/memcache.git/commitdiff/27c2d0a

hefox’s picture

Note that I think I used this patch for use with acquia enviroment to my memory, not sure if the upgraded their memcache since.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.