Drupal coder

Disable Drupal's page cache for some pages

We all know our Drupal sites can gain a huge performance boost by enabling page caching. But sometimes, you want to exclude certain pages from being cached.

One option to do such a thing is using a small module called CacheExclude.

You might also opt to program this yourself in your own modules by setting the cache variable to FALSE. Variables can be set temporarily for the current request by setting the global array conf.

A small example might clarify things. We're disabling caching on the front page here (not a thing you'd like to do every day, but it's an example ;)).

if (drupal_is_front_page()) {
  $GLOBALS['conf']['cache'] = FALSE;
}
November 12, 2008Drupal, module development, performance

Comments

Thank you.. this code is useful..

Thanks, this is useful!

In Drupal 6, should this code go in hook_init or hook_boot? The docs at http://drupal.org/node/114774#hook-boot-init seem to imply hook_boot would be appropriate, but I'm not completely clear.

Yaa i have used your suggested way. now i got solution.

It is the nice way to clear the cache in drupal. But can you also explain it regarding the boost module.

It is also same like this?

Indeed, Wim. Or hook_boot would work to.

Thanks for the tip Davy, I was just looking for this! It might be good to mention that this piece of code should go in hook_init.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options