3

We have a Drupal 7 site whose content is split into geographic regions. The concept is that page view blocks and filters will display region specific content based on the users IP address or selection of their country, the page URL is the same throughout. The issue we now have is that Drupal cache and Varnish cache are not regionally aware in that the cache is built up by the first visit upon start and clearing of cache so the wrong content gets displayed to a user who wishes to view content for his region, because someone before him opened the same page from another region. Any ideas?

1 Answer 1

2

Possible solution of separating your caches, by regions, in Varnish is to use GeoIP VMOD: https://github.com/lampeh/libvmod-geoip

Simple example:

put country code to hash

sub vcl_hash {
        hash_data(req.url);

        if (req.http.host) {
                hash_data(req.http.host);
        }
        else {
                hash_data(server.ip);
        }

        # separate caches by countries
        hash_data(geoip.client_country_code());

        return (hash);
}

Now caches for different countries will be different. Of course, you still need to take care about page generation in Drupal, it should provide different content for different regions too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.