Prevent Drupal from caching your module's output

Well, it's been an incredibly long time since I've written anything, so here's a little something to get started again.

I wrote a in-house Drupal module for one-use ticket file streaming. Basically, a unique identifier is used to stream the file, then is discarded, making the url invalid after one use. Everything worked fine for logged-in users, but just today I noticed a giant hole: users who are not logged in can access the file as much as they want, thanks to Drupal's caching system.

I'm not knocking the caching system, if fact, it's working exactly the way it's supposed to. But that's counter productive for my needs. I posted my predicament on #drupal, and Crell pointed me right to the solution, using a module he wrote to disable caching for specific pages.

If you want to disable caching for your module, you need to set the global configuration for caching to false in your hook_init() like so:


function audiostreamer_init() {
$GLOBALS['conf']['cache'] = FALSE;
}

So, next time you need to disable caching in your module, you know what to do.

Caveat emptor: Disabling caching will affect your site's performance. Tread lightly.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Wow! No, drawback is not an issue. On examination of the nodeaccess function if one fetches nid, type, status and uid then there is no need to fetch the rest of the node before calling nodeaccess.I modified the KML module to fetch these elements for target nodes and compare the changed times as it went (for comparison to any cache built to see if it is out of date). This list of nodes is then passed down into the rest of the functions, the rest of the node data being fetched later with node_load of course.On a test system with over 1000 spatial nodes standard build time for kml/node is 6-7 seconds. Once cached this takes less than half a second to return.

Not sure what Mrugesh is on about, but this solution worked for me. Many thanks to you and Crell!

Its not that much clear!! Sorry!!

Hi,

You have suggested wrong way to prevent module from caching. I not going to criticize you. But i have tried it.

And more information u can also refer this link

http://api.drupal.org/api/function/hook_init/6

and read it.

Thanks,
Mrugesh Panchal

You sir, now have a friend for life. Thank you very much!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

The content of this field is kept private and will not be shown publicly.
Captcha
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
six minus three equals
Solve this math question and enter the solution with digits. E.g. for "two plus four = ?" enter "6".