Selectively Turn Off Drupal Caching

19th February 2010 - 2 minutes read time

It is sometimes necessary to turn off caching on certain pages on a Drupal site. This might be when trying to do something out of the ordinary, like write information to a file, or randomly generate a section of a template. The following code can be used to turn off caching just on the front page of the site.

  1. function theme_preprocess(&$vars, $hook) {
  2. if ($vars['is_front'] == true) {
  3. $GLOBALS['conf']['cache'] = false;
  4. }
  5. }

Adding false to the cache item of the conf globals array at run time will turn off the cache. This is within an if statement that checks to see if the current page is the Drupal front page so it will only be used on the front page.

This is a pretty simple solution, but it should be used with great care. Remember that you are turning off the cache and this will definitely have an effect on the performance of the site. Be sure of what you are doing when you turn off the cache!


In Drupal 7 this is controlled via a function called drupal_page_is_cacheable(). This takes a single boolean parameter of FALSE to turn off caching and TRUE to turn on caching.

Add new comment

The content of this field is kept private and will not be shown publicly.