caching - Is it possible to vary page caches (to have cache versions) with the same url and different cookie value (language)? -


we have multilanguage site , want cache e.g. page /about. english , belarusian pages have same url: /about, language stored in , detected cookies.

  • en: /about, cookie: site_lang: en
  • be: /about, cookie: site_lang: be

we have reverseproxy cache (symfonyhttp or varnish). when first user opens /about page en value in cookies, it's cached reverseproxy , browser. response headers:

cache-control max-age=600, public, s-maxage=600 last-modified mon, 27 apr 2015 21:48:34 gmt vary x-language ... 

what x-language:

since can't vary cookies (it lead have different cache versions each user because of @ least session id), vary custom header set apache.

so when user made request, apache parses site_lang cookie , adds parsed value custom header x-language. logic, reverseproxy knows do: return cache or forward request application if there no cache language header.

it works when second user opens /about page be value in cookies, apache parses language, creates x-language: be header , reverseproxy don't return cache en language forward request application.

but doesn't work when first user tries change locale localeswitcher on site. when tries click language link, browser returns local cached page , user's request not processed apache, of course.

so question, how handle situation, possible solutions. main requirement we don't want have language in url.

thank you.

you can customize varnish uses hash key in vcl_hash function, see here.