I am using https://www.drupal.org/project/masquerade on a rather prominent place and I've found that the switch that allows admins to switch back from the user they masquerade as is getting cached.

Obviously, I could put that widget on some page that's only accessible to admins, but then it's less usable for those.

So I would like to avoid caching for people who are masquerading. Any pointers to which hook I should use?

Comments

killes@www.drop.org’s picture

Turns out this is easy to do:

in


hook_block_view_alter(&$data, $block) {
  switch ($block->delta) {
    case 'masquerade':
      // suppress authcache caching of pages when a user is masquerading:
      if (isset($_SESSION['masquerading']) || count(variable_get('masquerade_quick_switches', array()))) {
        if (function_exists('authcache_page_is_cacheable') && authcache_page_is_cacheable()) {
          authcache_cancel(t('Not caching pages when masquerading.'));
        }
      }
      break;
  }
}
mr.baileys’s picture

If you want to avoid caching while masquerading, I think using hook_authcache_account_exclude() might be better:

/**
 * Implements hook_authcache_account_exclude().
 */
function example_authcache_account_exclude() {
  // Prevent caching when masquerading as another user.
  if (isset($_SESSION['masquerading'])) {
    return t('Caching disabled while masquerading');
  }
}
znerol’s picture

Category: Feature request » Support request
Status: Active » Fixed

Thanks @mr.baileys for answering this request. Please open a new issue if there is still something unclear.

Status: Fixed » Closed (fixed)

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