How to configure VCL to cache pages when there's a language cookie


#1

I’m actually having a lot of problem trying to get Varnish Cache to work. I’m trying to accomplishing caching of pages when there’s a presence of a language cookie but X-Cache is always missing.

So far I have only gotten it to work only when when a new user comes to the page with no existing cookies such as doing a repeated (curl -I URL). Only in this case, X-Cache will hit.

But if there is an existing cookie from a returning user (a language cookie is needed so as to serve the correct language content to the returning user, meaning each URL has a few different versions and the respective version for each language is served based on the cookie) - In this case, X-Cache is always missing.

So how do I vary page caches (to have cache versions) with the same URL and different cookie value (language) or how to separately cache pages based on value of a specific cookie?

Below are the headers when I do an curl -I

HTTP/1.1 200 OK
Server: nginx
Content-Type: text/html
X-Powered-By: PHP/5.5.9-1ubuntu4.9
Set-Cookie: WebSiteLang=fr; expires=Sun, 05-Jun-2016 08:42:24 GMT; Max-Age=31536000
Content-Length: 21178
Accept-Ranges: bytes
Date: Sat, 06 Jun 2015 08:42:24 GMT
Via: 1.1 varnish
Age: 0
Connection: keep-alive
X-Served-By: cache-sin6922-SIN
X-Cache: MISS
X-Cache-Hits: 0
X-Timer: S1433580143.701342,VS0,VE722
Vary: WebSiteLang

Thank you.


#2

Hi-

In our environment, HEAD requests don’t cluster so it won’t accurately represent cache behavior. Use GET requests: curl -svo /dev/null <URL>

Typically we will see customers key language-specific responses off of the Accept-Language: request header and Vary on the language rather than use cookies.

We will by default mark any object with a Set-Cookie response header as a PASS object.

Please be sure to use our default VCL template in your implementation.

You might also want to look at Simon’s blog post on cacheing with tracking cookies: