Drupal: disable caching for an entire module

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 someresultsthat 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:

In that snippet, you’ll want to change ‘url_of_your_module’ to a string unique to the path of your module. For instance, if your module lives a http://my.web.site/the-wrapped-module/, then you could put ‘the-wrapped-module’ in the place of ‘url_of_your_module’.

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.