Multi country cache problem

Hauke Lampe lampe at hauke-lampe.de
Wed Oct 19 19:39:55 CEST 2011


On 19.10.2011 17:29, Maikel Brouwer - Songteksten.nl wrote:

> if ($country == 'be') {
>   //display stuff
> } else {
>   //display other stuff)
> }
> 
> The problem is that when someone from 'be' visits the page when it's not
> yet cached the code in the 'be' block will be cached. When someone from
> 'nl' visits the page it will see the 'be' block.

I'd probably resolve the GeoIP country in VCL and set an HTTP header:
| set req.http.X-Country-Code = geoip.client_country_code();

The webserver then would have to add a "Vary: X-Country-Code" header to
country-specific pages. E.g. in apache:
| Header merge Vary X-Country-Code

varnish would cache one copy of each object for every country code, so
you might want to reduce the additional header to "be-or-not-be".

A better option could be to use ESI and cache the HTML code for pages
and ads separately. I haven't tested ESI with varnish yet, so I cannot
give an example here.


Hauke.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20111019/97df77d5/attachment-0003.pgp>


More information about the varnish-misc mailing list