I've been succesfully using Authcache with Drupal Commerce with great results, except for one annoying situation: drupal_set_message().

Being a Commerce website, there's a lot of messages ("item added to cart", "item removed from cart", etc) that need to be displayed after the user performs an action. Drupal core uses drupal_page_is_cacheable(FALSE) to bypass caching when a message is set, but Authcache doesn't respect this as far as I know...

My ugly solution was to use the Cache Expiration module and patch core to programatically invalidate the cache for the redirect/q page when a message is set... it's fugly but works... just wondering whether this kind of scenario has been contemplated and whether I'm just doing things wrong....

Thanks!

Comments

znerol’s picture

Actually the mechanism for message handling in authcache is supposed to work in the following way.

  1. Whenever a page is rendered, authcache checks if there are messages on the page. In order to detect pending messages authcache implements hook_process_page (see authcache_process_page().
    361 /**
    362  * Implements hook_process_page().
    363  *
    364  * Prevent caching pages with status messages on them. Note that due to the
    365  * fact the messages are only added in template_process_page, we also need to
    366  * use the process-hook.
    367  */
    368 function authcache_process_page(&$variables) {
    369   if (!empty($variables['messages']) && authcache_page_is_cacheable()) {
    370     authcache_cancel(t('Status message on page'));
    371   }
    372 }
    
  2. After a page is rendered and before it is saved to the cache, authcache once more checks whether there are pending messages. If this is the case, a cookie is set which enforces that the client will bypass the cache on the next request. This is necessary in order to prevent messages from piling up in the session but never shown to the user. Throughout the authcache code base, this mechanism is called preclusion. See authcache_authcache_preclude()
    969 /**
    970  * Implements hook_authcache_preclude().
    971  */
    972 function authcache_authcache_preclude() {
    973   // Skip the cache on the next page request when messages are pending.
    974   if (drupal_set_message()) {
    975     return t('Pending messages');
    976   }
    977 }
    

If this default implementation is not enough, you may call authcache_cancel any time before hook_exit to prevent the current page from being saved to the cache and you also may implement hook_authcache_preclude if you need to ensure that the next page request coming from the same client will not be served from the cache.

It would be worthwhile to try investigating why the default implementation does not suffice in your case. I'd approach this problem by first checking whether the theme is doing funny stuff in the page.tpl.php. Another thing to check is whether messages are being set after the page is built (e.g. from within templates or theme functions).

znerol’s picture

Status: Active » Postponed (maintainer needs more info)
alexweber’s picture

Hi, my exact situation revolves around Drupal Commerce and standard "added/removed" from cart messages... i'm using zurb foundation which displays messages in a modal, so that could be related, i'll investigate further

znerol’s picture

Ok, do you use the pattern from #1799678: put status messages in reveal-modal?

znerol’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)