Selectively Turn Off Drupal Caching
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.
function theme_preprocess(&$vars, $hook) {
if ($vars['is_front'] == true) {
$GLOBALS['conf']['cache'] = false;
}
}
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!
Comments
Post new comment