menu cache is not cleared for user when role is updated

firebus - November 6, 2007 - 17:52
Project:Memcache API and Integration
Version:5.x-1.6
Component:Code
Category:bug report
Priority:critical
Assigned:firebus
Status:active
Description

i've noticed since i started using memcache that when i update the roles for a user, they don't see the new menu items they are entitled to.

if i cache_clear_all the menu cache, suddenly they can.

i suspect that menu.module issues a wildcard cache_clear_all when a user is updated. since memcache can't handle wildcards, we get no love.

memcache probably needs to flush the entire cache_menu bin on a user edit that involves a role change. this is unfortunate, but probably rare in most use cases. i'm not sure how easy/not easy it is to construct a hook that can tell when the role is changing.

#1

firebus - November 20, 2007 - 06:04

user.module
function user_edit_submit
line 1500 or so

cache_clear_all($account->uid .':', 'cache_menu', TRUE);

replace with:

$languages = locale_supported_languages();
foreach (array_keys($languages['name']) as $locale) {
  cache_clear_all($account->uid . ':' . $locale, 'cache_menu');
}

i'll provide a patch after i upgrade to 5.3...

#2

robertDouglass - November 25, 2007 - 21:43

Please try putting that code in memcache.module, memcache_user hook ($op == 'update', I think), and see if that takes care of the problem.

Is this a core bug?

#3

firebus - December 5, 2007 - 01:11

imo it's a core "by design". i found a similar issue with advcache's path caching, which i'll report separately once i've found the code.

any time core uses a wildcard to clear keys with a specific prefix, memcache isn't going to handle it gracefully and the cache will not be cleared for those keys.

since memcache is patching core for the serialization issues, i don't think it would be too evil to patch core for the wildcard issues, however, it's definitely nicer if we can do it with the hook. op might be save instead of update (i think menu_cache clears the cache in save)

i'll take a look and give you a patch!

#4

firebus - December 24, 2007 - 02:29

the solution in http://drupal.org/node/199483 (in case of wildcard, flush the whole bin) works against your proposed solution here.

we have to at least patch menu.inc to disable the wildcard call.

the replacement code can live in menu.inc or in memcache.module, but including it in menu.inc is more readable.

#5

robertDouglass - July 18, 2008 - 20:28

@firebus: can you provide an update on this issue and propose a fix?

#6

robertDouglass - July 18, 2008 - 20:32
Priority:normal» critical

#7

firebus - July 18, 2008 - 21:04

i'm running happily with the above code, but it would be nicer to test if memcache is enabled, and also test if locale is enabled.

since we now clear the whole bin for all cache_clear_all calls with wildcards, this is no longer a bug. however, we definitely save some cycles by computing the correct keys to clear instead of dropping the whole bin.

here's a patch against user.module in 5.8. i'm not sure if it makes sense to roll this into cache-serialize-patches or if you want a different patch file for non-serialization related issues.

perhaps there's been some changes around the wildcard cache_clears issue that supercedes this issue, or would allow for a memcache_user hook fix - let me know. i haven't been keeping up with that issue...

AttachmentSize
user.module.patch1.06 KB
 
 

Drupal is a registered trademark of Dries Buytaert.