Multi country cache problem

Hugo Cisneiros (Eitch) hugo.cisneiros at
Wed Oct 19 19:15:43 CEST 2011

On Wed, Oct 19, 2011 at 1:29 PM, Maikel Brouwer -
<mbrouwer at> wrote:
> I've got the following problem. Maybe someone has a solution for it. My
> site is visited by two countries (Belgium and Netherlands). I have two
> different advertisement agencies to display ads for the specific
> countries. This means that every page how something like this:
> 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.

You can modify the vcl_hash to cache content based on client's ip.

For example, you can create an acl with the IP ranges from two countries:

acl country1 {

acl country2 {

Then on vcl_hash:

sub vcl_hash {

   if ( {
    } else {

   if (client.ip ~ country1) {
   } elseif (client.ip ~ country2) {

This would create TWO cache entries (it will duplicate your cache
size), one for country1 and one for country2. Actually, if the user
isn't from country1 and country2, it'll create another cache entry for
the rest (else). You can change this logic as you wish. The hash_data
is the key to create multiple cache entries depending on any usual
variable on the vcl.


More information about the varnish-misc mailing list