I want to exclude certain roles (of which I am sure they do not alter output) from the authcache key, so the same cache is used as users that have the same roles except those certain roles. For example roles that give access to certain admin pages which aren't cached.

Just to make sure, is it sufficient to implement hook_authcache_key_properties_alter()?

<?php
function hook_authcache_key_properties(&$properties) {
 
$properties['roles'] = array_diff($properties['roles'], array('admin reports', 'moderator files'));
}
?>

Thanks in advance.

Comments

#1258730: Users with multiple roles using same authcache is somewhat related, but in 7.2 "authcache_key_generator" is only available for anonymous users.

For authenticated users, you can alter the key-properties. Try something like this:

<?php
function hook_authcache_key_properties_alter(&$properties) {
 
$equivalent_roles = array(2, 3, 4);
 
$substitute_roles = array(2);
 
$substitutable_roles = array_intersect($properties['roles'], $equivalent_roles);
  if (!empty(
$substitutable_roles)) {
   
$normalized_roles = array_diff($properties['roles'], $equivalent_roles);
   
$normalized_roles = array_merge($normalized_roles, $substitute_roles);
   
$properties['roles'] = $normalized_roles;
  }
}
?>

Disclaimer: I just left my bed and you should not expect that this code is bug-free. But it should get you an idea on how it might work.

Status:Active» Fixed

Thanks!

Status:Fixed» Closed (fixed)

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