Frontpage cache handling in multi-langual Drupal website

Joris Snoek | 23/02/2010 - 14:46

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:

  1. /**
  2.  * Override cache handler
  3.  */
  4. $conf = array(
  5. 'cache_inc' => './sites/all/modules/custom/cstcache/cstcachecache.inc'
  6. );

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

Over Joris Snoek

Joris Snoek is Full time Drupal verslaafd, Project leider bij Lucius & Technology-freak. Tevens afgestudeerd in bedrijfskundige informatica en houdt veel van: muziek productie, snowboarden, tennis & fitness. En: heeft een zwak voor Duitse herders.

Over Peter Terpstra

Peter Terpstra is accountmanager bij Lucius.

Relatiebeheer en trajectbegeleiding van begin tot eind vallen onder zijn hoede.

Laatste tweet van Joris

joris_lucius: Looking into #mongodb #drupal implementation. Looks promising so far. #performance http://drupal.org/project/mongodb

Volg alle tweets van Joris

Zoeken