Score:0

How to distribute Varnish cache differently to different kind of requests?

cn flag

I have a redirect in my store that shows a different store view based on the client's location. It reads the header via Fastly and redirects the customer to a different store view using every time the same URL.

When there are many customers accessing the store the cache is mixed, even with the redirect working the cache is distributed to all customers in any location, making customers from the UK see the US store view.

How could I customize the cache block via VCL file to not just redirect by distributing cache based on the location?

Score:0
ma flag

You will need to hash the requests using that header, telling Varnish requests with differences in that header generates diferent responses.

Just add something like this to your vcl, replacing X-Your-Location-Header with your header's name:

sub vcl_hash {
  /* Custom header hashing */
  if ( req.http.X-Your-Location-Header ) {
    hash_data(req.http.X-UA-Device);
  }

See https://www.varnish-cache.org/docs/trunk/users-guide/vcl-built-in-subs.html#vcl-hash

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.