This is a follow up to an email with @znerol. I asked if it was possible to load Drupal status messages with ESI, but this didn't seem feasible. The use case was after logging in, Drupal displays a "User [username] has logged in" message. This disables caching on the home page for me, when what I really want is to always deliver this page from cache because of the many logins that happen on this site. It's a simple portal site that delivers a page of links to a logged in user based on their role, so the home page should always be delivered from cache.

Instead of trying to load this status message with ESI, I'm wondering if I can programmatically disable it so that the page can be delivered from cache. I have an ESI block with a welcome message and their username anyway. My question is, what does Authcache look for that causes it to disable caching? If I can disable the status message after login, then maybe this page can be cacheable. There are also some modules that allow for disabling of status messages, so it's possible those might work. Thanks!

Comments

znerol’s picture

I think that drupal does not emit any message when logging in. The message could be coming from a third party authentication module or from a login action/rule. If you cannot figure out who is putting this message on the page, I recommend to capture a backtrace to the PHP error log using the following fragment:

ob_start();
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
error_log(ob_get_clean());

Place this fragment into the drupal_set_message function definition (around line 1776 in includes/bootstrap.inc).

Authcache decides whether the next page request should not hit the cache from within authcache_exit:

  // Disable authcache on next page request e.g., if there are messages pending
  // which did not manage it onto the current page.
  $reasons = module_invoke_all('authcache_preclude');
  if (!empty($reasons)) {
    _authcache_preclude(reset($reasons));
  }

So if any hook_authcache_preclude implementation returns something <> null, the nocache-cookie will be set. Authcache supplies its own hook-implementation which looks like this:

/**
 * Implements hook_authcache_preclude().
 */
function authcache_authcache_preclude() {
  // Skip the cache on the next page request when messages are pending.
  if (drupal_set_message()) {
    return t('Pending messages');
  }
}

This means that if any message is pending during hook_exit the next page request will bypass the cache.

It might be possible to suppress the invocation of this function by altering away the implementation using hook_module_implements_alter. However then the messages still would pile up in the session and the next time the user accidentally hits a non-cached pages they would be displayed all at once.

znerol’s picture

Status: Active » Fixed

I suppose no news is good news. Reopen if you need more information.

Status: Fixed » Closed (fixed)

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

vinmassaro’s picture

FWIW, this was the CAS module, and I ended up finding a configuration for a message after logging in. Removing this message did not set one on login, and Authcache Varnish then returned a cache hit.