How do I setup Drupal/Varnish caching so Content Editors don't see browser-cached pages after logging in?

drupal.stackexchange https://drupal.stackexchange.com/questions/246143

Question

I've got a bit of a situation going on with our caching solution and would love some input.

We use a solution of HAProxy -> Varnish -> Apache. HAProxy terminates SSL and sends that to Varnish which then requests from Apache if needed.

We are using Drupal 7, Purge, and Cache Expiration. We have Cache Expiration set to use external expiration and include the baseurls. Our sites have "Minimum cache lifetime" set to "none" and "Expiration of cached pages" set to "6h".

The Varnish cache always has the correct versions of the cached pages and those get expired correctly.

If an anonymous user visits a page, say node/123, and then logs in and subsequently navigates back to the same page the browser still serves the browser cached version of the page. This is the expected behavior from Drupal as I would expect the page to stay cached for an anonymous user.

Our content editors are required to reload the page (F5) and think there is an "error" because they need to perform this in order to see the expected, authenticated, version of their page.

How do other administrators who allow editing on production instances tackle the issue?

I toyed around with the idea of shortening the cache lifetime that comes out of Varnish, but that feels like a band-aid (30s cache vs. 6h). I also toyed with the idea of removing the cache headers coming out of Varnish, but allowing Varnish to hold the cache for its lifetime.

I'd like to be able to cache responses to keep the load off of our server if at all possible.

Thanks in advance!

Was it helpful?

Solution 2

I ended up solving this by making sure that our proxy sent out the following header for cacheable pages.

Cache-Control: public, max-age=0

The behavior I was experiencing was due to page_cache_maximum_age being set, and in reality I didn't want that being sent to clients, only my caching server.

sub vcl_backend_response() { if (not static content && !beresp.uncacheable) { unset beresp.http.Cache-Control; set beresp.http.Cache-Control = "public, max-age=0"; } }

OTHER TIPS

See the answer to this question: https://drupal.stackexchange.com/a/117984/3279

Example usage for the D6 varnish module can seen here: https://www.drupal.org/node/738420

So, you could do a hook_form_alter in a custom php module for D7 that adds an additional submit handler to your nodes that basically calls the D7 equivalent code to clear the varnish caches for the 1 node path path/aliases in question.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top