I'm setting up Authcache to work with Varnish as a backend.

It comes with an excellent default.vcl which is very well documented. It has the following section on cookies. Varnish skips the cache if cookies are enabled, so the following example would appear to remove all cookies so it can cache.

However I've found if I un-comment this section Authcache stops caching. If I leave it commented out then it continues to cache and cookie functionality seems to work. (e.g. I have cookies which remember the state of facets across page refreshes and they continue to work).

Isn't this the wrong way around?

(I'm using Authcache debug to test for caching).

// * Example 2: Remove all but
  // * - the session cookie (SESSxxx, SSESSxxx)
  // * - the cache invalidation cookie for authcache p13n (aucp13n)
  // * - the NO_CACHE cookie from the Bypass Advanced module
  // * - the nocache cookie from authcache
  // *
  // * Note: Please also add the has_js cookie to the list if Authcache Ajax
  // * is also enabled in the backend. Also if you have Authcache Debug enabled,
  // * you should let through the aucdbg cookie.
  // *
  // * More information on:
  // * https://www.varnish-cache.org/docs/3.0/tutorial/cookies.html
  // */
  //if (req.http.Cookie) {
  // set req.http.Cookie = ";" + req.http.Cookie;
  // set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
  // set req.http.Cookie = regsuball(req.http.Cookie, ";(S?SESS[a-z0-9]+|aucp13n|NO_CACHE|nocache|aucdbg)=", "; \1=");
  // set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
  // set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
  //  if (req.http.Cookie == "") {
  //   unset req.http.Cookie;
  //  }
  • Authcache Debug for anonymous users does not work well together with Varnish. I guess that the debug widget indicates misses because the aucdbg cookie is removed from the request by this VCL snipped. See also #2157165 in the issue queue. – znerol Dec 19 '13 at 19:50
  • @znerol Heh sorry I'm also the person that raised that bug. At this point I wasn't sure if I was doing it wrong or it was a bug. I'll write up a proper answer. – Dominic Woodman Dec 20 '13 at 16:43

Copy pasta of Znerol's excellent answer to the incorrect bug I raised:

The VCL shipping with Authcache Varnish needs to be adapted for Authcache Debug. The widget uses a cookie (aucdbg) with a unique value for each request in order to distinguish between cache hits and misses.

By default the standard cache policy kicks in for anonymous users. I.e. requests having a cookie will be passed to the backend by Varnish. When you use ab for testing, no cookies will be sent along with the request and therefore the cache actually kicks in. When testing with the browser, the aucdbg and js cookies are added by JavaScripts and therefore the requests are bypassing the cache.

Look for Example 4: Trigger key-retrieval for all users, including anonymous. in vcl_recv and enforce key-retrieval for all users. When this fragment is enabled, requests for anonymous users will be handled exactly like those for authenticated users and the default varnish cache policy will be disabled.

Un-commenting section 4 in the Authcache default.vcl solved this problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.