Drupal: disable caching for an entire module
0 Comments Published April 25th, 2009 in Free Software/Open Source.I have a legacy php application that had to be integrated into a Drupal site, so I wrapped it in a simple drupal module. The code needs to run for anonymous users.
The wrapping worked fine, but the Drupal cache really gets in the way sometimes. For instance, my legacy code does not use the drupal_set_message functions when a form submit fails. That means that the page that tells the user they made a mistake gets cached, leading to all sorts of unexpected results.
I looked around for a way to disable the Drupal cache for an entire module, but only found some results that didn’t quite do the trick. But then I stumbled across the CacheExclude module, which does exactly what I want. I didn’t want to include yet another module for something as simple as this, so just duplicated the ‘magic’ lines in my module:
function your_module_name_init() {
// We don't want caching for this module
if (drupal_match_path($_GET['q'],'url_to_your_module/*')) {
$GLOBALS['conf']['cache'] = FALSE;
}
}
And that does the trick. Now, I’m by no means a Drupal expert, so there may well be a better way to do this. Feel free to leave a comment if you know how.
![[Play OGG]](/blog/wp-content/themes/3k2redux-klein/images/play_ogg_small.png)


0 Responses to “Drupal: disable caching for an entire module”
Please Wait
Leave a Reply
You must login to post a comment.