Frontpage cache handling in multi-langual Drupal website

13 Sep 2011

Joris Snoek
Digital Consultant
+31 (0)20 - 261 14 99

A few months ago we ran into a caching case on a global Drupal multi-site.
The site runs on 4 languages: English (main), Dutch, Spanish and German.

We set up the Drupal standard caching system wich is handled per url by Drupal.

So every page on a unique url is cached by Drupal.
When a anonymous visitor hits the site, Drupal serves completetly from cache, wich gives a tremendous performance boost.

The problem

All URL are unique (we used language prefixes in URL), except one...: Frontpage !

So what happened: after cache time expired and Drupal starts to re-cache; the frontpage was cached by the first visitor. And if this was for example a German person, frontpage was cached in German for all visitors! Cos Drupal was also set to: check vistor's browser language and show that language.

Here is how we handled it

You can alter the standard Drupal cache handler in a custom module. To accomplish this, add for example the following code in your settings.php:

* Override cache handler
$conf = array(
'cache_inc' => './sites/all/modules/custom/cstcache/'

In that .inc file you can completely alter the cache handling. By using some core functions and customization we managed to solve this problem.

Related links

Cache API
New Cache Router release!
A beginner's guide to caching data


Nóg meer
kennis nodig?

Check ons ons blog archief >