Authcache: 1.0 release & "multi-variant" caching

simg's picture

Hi All,

Thought you might be interested to know that I've just posted a 7.x-1.0 release of Authcache.

I've also added an interesting feature to the dev branch. That is, the ability to have custom authcache keys. This might be useful for example if you have a lot of roles on your site but you don't want to cache different content for each of them. It would also be useful if you wanted to cache different content for different devices eg mobile / desktop etc.

It's 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.

eg:

$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 :)

Comments

Great news!

fbdo's picture

Thank you, simg, for your efforts. This module is one I know which make THE difference in the performance for a logged user. I will use immediately for one of my customers.

Amazing Timing

whoisinkus's picture

This is a great addition to this module. I came across authcache for it's main purpose of caching authorized user content, but I also serve different content from different GEOIP regions and need to cache those separately. The authcache_key_generator configuration should work to serve those needs exactly.

Well done.

Great to hear

mengi's picture

Great to hear! Can't wait for my next project to use this. Thanks for all the effort!

High performance

Group events

Add to calendar

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week