How to keep Drupal from caching a page

Submitted by jrb on Mon, 10/18/2010 - 17:44

I ran across a problem on a site today where some custom voting code had stopped working correctly.  Eventually, I figured out that the actual problem was due to the page being cached, so it wasn't showing the updated results.  I didn't want to turn off caching so, my next step was to figure out how to turn caching off for a particular page.  The Google found CacheExclude, a module that allows you to do just that-- turn caching off for specific pages. 

That module did the job, but I wanted to know exactly how it worked.  Looking at the source, the "magic" was basically a single line:

$GLOBALS['conf']['cache'] = false;

In my case, the pages in question were created by custom code, so I just added that line to my code rather than adding another module. That will prevent Drupal from caching the page.

 

Tags: