Brief overview of my setup:
Authcache 2.X (2013-Apr-04)
File Cache 1.0-beta2
Cache Expiration 1.0-beta1
Ubuntu 10.04 LTS 64-bit
PHP Memory = 256MB
27 Roles enabled in Authcache

Now that the Cache Expiration module works with Authcache 2.X, I've almost got the perfect cache setup for the site. The issue I am having is due to the amount of roles I have enabled for Authcache. During a node save, when the cache for the node and various other pages are being cleared, I am running into fatal errors due to PHP running out of memory as it is working with the large arrays.

Here's one of the errors I've gotten:
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 71 bytes) in <drupal directory>/sites/all/modules/authcache/ on line 34

If I drop the enabled roles down to 14, a node save will go through fine, although with a pretty noticeable delay as the many different cache entries are being cleared.

I briefly played around with alternative arrays that use less memory (SplFixedArray & Judy Array), but haven't had any luck so far in getting them to work correctly.

Just seeing if anyone has any suggestions, or whether or not this could be made to work. The site could really benefit from this caching, but I'm starting to think that it might be impossible with the amount of roles I would need to have caching enabled on.

Thanks all.

#4 1963756-Memory-issues.patch2.76 KBznerol
Members fund testing for the Drupal project. Drupal Association Learn more


znerol’s picture

When enabling 27 roles, then a total of 134,217,726 combinations of roles are possible. Authcache tries to enumerate the key-values for all of them in order to be able to purge all variants from the cache. For 14 roles this value drops to 16,382.

It would help if you could outline the way you are working with your roles and whether each possible combination actually produces different markup

ronin17’s picture

Thanks for the help. Here's an outline of the roles being used:

3 Default Drupal Roles - admin, anonymous, and authenticated.
2 Roles that determine basic permissions for accessing private content. All users either have one of these, but not both (although not impossible).
22 Roles that give users editor permissions to the various Library sections on the site. There are 62 users with some combination of these roles.

I would go ahead and just disable the editor roles in Authcache, but they really are the ones that would benefit the most from caching.

Out of the 62 users that have at least one editor role, there are definitely duplicate combinations. What if I only added the combinations that were currently being used instead of having Authcache generate the full amount of combinations? There are probably less than 30 combinations of editor roles + other roles.

Ideally I would want to automatically generate the current combinations from the current active user accounts, and then add that combination into Authcache. This is definitely a little bit of a hacky way to go about this, but changing the way roles are being used on the site isn't really an option at this point.

Thanks again!

ronin17’s picture

So here is my current solution to this problem, admittedly it isn't my ideal solution, but I wanted to get 2.X running as soon as I could to see how the performance was.

The main part of the modification is done in the authcache_authcache_account_properties_info() function in authcache.module. Here's a quick view of the changes:

// Combine remaining roles
$roles = array_keys($roles);

// Remove editor roles
$basicroles = array(3,21,24);
$editorroles = array_diff($roles, $basicroles);
$roles = array_diff($roles, $editorroles);

// Add current role combinations
$choices = array_merge($choices, _authcache_get_combo($editorroles));

$choices = array_merge($choices, _authcache_comb($roles));

I'm basically getting any of the editor roles that are enabled in Authcache and then running them through a new function that will return only the used role combinations that are in use.

Here's what the function looks like that is retreiving the combinations:

function _authcache_get_combo($roles) {
  $uids = array();
  $combos = array();
  $authid = array(2);

  // Use $query for readability
  $query = 'SELECT DISTINCT(ur.uid) 
    FROM {users_roles} AS ur
    WHERE ur.rid IN (:rids)';
  $result = db_query($query, array(':rids' => $roles));

  foreach ($result as $row) {
    $uids[] = $row->uid;
  $users = user_load_multiple($uids);
  foreach ($users as $user) {
    if ($user->status == 1) {
      $rl = $user->roles;
      $rl = array_keys($rl);
      $rl = array_diff($rl, $authid);
      if (!in_array($rl, $combos)) {
        $combos[] = $rl;
  return $combos;

Here I am getting all of the users that are currently using any of these roles, and then creating a list of role combinations that are being used by the current active users. I did have to remove the authenticated role from the list, but other than that it's pretty straightforward.

With these changes, I am able to add even more editor roles into Drupal and not have to worry about the increase in possible combinations overloading PHP.

So far everything is working great, 2.X is a really nice and the ability to use the Cache Expiration module now makes this an almost perfect setup.

Comments and critiques on the code are welcome and appreciated!

znerol’s picture

2.76 KB

Would it help if the role-combination-generator would be pluggable? I've attached a possible solution. With the patch you may override the default combination-generator by simply supplying the name of your own function as a config-variable in settings.php:

$conf['authcache_role_combine'] = '_my_function';
znerol’s picture

Status: Active » Fixed

Fixed in 0e17381

Status: Fixed » Closed (fixed)

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

toci’s picture

I'm using drupal 7.33 - php 5.4
I got exactly the same situation. I have many roles (17). When I change some data in the profile page I get the following error.

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 46 bytes) in /var/www/html/MY_SITE/sites/all/modules/authcache/modules/authcache_enum/ on line 94

If I reduce the number of roles which are using authcache, the problem disappear.

Look like the code in the patch above should solve the problem but the code is totally different from the actual version.
I've checked the versions: 7.x-2.0-beta3+31-dev and 7.x-2.0-beta4 but the code is different than the patch.

Is there a way to correct the problem or at least a work around ?

Thank !!

znerol’s picture

Please open a new support request, do not comment on closed issues.