Hello, I could not find a solution for the following:

Is there a solution (eventually a hack) so that users with different roles use the same authcache?
My users are authenticated (loggedin) users with different roles but they use and share the same information.

Jan Walhof


spazfox’s picture

Version: 6.x-1.0-rc1 » 6.x-1.0-rc2
Category: support » feature

I would like to see this, too. Although there are several different roles my users might have, I really do not need to provide them with different pages or caches (their roles determine which nodes they have access to, but if they have access to it from one of their roles, the content is the same regardless of which roles they have). I was hoping just checking the "authenticated user" option would handle this use case, but it does not appear to work that way (and see #737762: How authcache handles users with multiple roles).

It would be great, though, if we could select just "authenticated user" in the admin settings and have a cache that works for all authenticated users, regardless of any additional roles they might have. I'm currently building a crawler/cache warmer for my site, and it seems that under the current configuration, I will need to crawl the pages using every possible combination of roles on the my site. Yikes! I can't imagine that janwalhof and I are the only ones in this situation.

simg’s picture

funny, I was thinking of developing *exactly* this for the D7 version (need to discuss with Jonah).

what I have in mind would be to extend authcache by providing a hook to generate a custom authcache key. essentially, de-coupling it from the users roles, whilst at the same time keeping the default behaviour exactly the same for those who want it.

spazfox’s picture


That would be great, simg! It would be nice to not have to hack the $keys variable to make my cache warming work.

spazfox’s picture

simg, is this implemented in the D7 dev version?

simg’s picture

>simg, is this implemented in the D7 dev version?

no ...

simg’s picture

This feature is now in the 7.x-1.x-dev branch. (If there's demand, I might add it to the D6 version)

Very easy and powerful.

To use, you just need to set a configuration variable in settings.php to point to the name of a function you want to use and then write that function to generate your cache keys.


$conf['cache_backends'][] = 'sites/all/modules/contrib/filecache/filecache.inc'; 
$conf['cache_backends'][] = 'sites/all/modules/contrib/authcache/authcache.inc';
$conf['cache_default_class'] = 'DrupalFileCache';
$conf['cache_class_cache_page'] = 'DrupalFileCache';

$conf['authcache_key_generator'] = 'authcache_samecontentforall';

// Sample key generator functions
function authcache_samecontentforall($user) {
  if ($user->uid != 1) {
    return '';// all non-admin users get the same content
  } else {
    return substr(md5(drupal_get_private_key()), 0, 6); //except "admin" who has a hard to guess cache key 

function authcache_mobilecache($user) {
  $device_group = writeyourownbrowsersniffer(); // you need to write your own browser sniffer
  $keys = implode('.', array_keys($account->roles));
  return substr(md5($device_group . $keys . drupal_get_private_key()), 0, 6);

You can put your functions anywhere you like. I'm lazy, so I've left mine in settings.php but you could include them via a module or whatever.

Using this technique is very powerful in that you can cache separate content for different groups of users based on any criteria you like. You could for example use this for caching content separately for mobile users for example (or any combination of roles / devices / whatever) as per the above example.

If you don't set an authcache_key_generator, authcache will use it's default setting and carry on working exactly as before.

Enjoy :)

znerol’s picture

Issue summary: View changes
Status: Active » Closed (outdated)