[mod_python] How can I turn off apparent caching of python code?

Jorey Bump list at joreybump.com
Wed Aug 25 12:04:59 EDT 2004

Graham Dumpleton wrote:

> BTW, various problems I have seen with things appearing not to be 
> reimported correctly
> are actually because of intermediate proxy servers caching stuff. Thus 
> need to explicitly
> say not to cache stuff in response, although error pages can stuff that 
> up also.

Within your application you can do this:

  req.headers_out['Pragma'] = 'no-cache'
  req.headers_out['Cache-Control'] = 'no-cache'
  req.headers_out['Expires'] = '-1'

Or you can simply set the headers in httpd.conf or .htaccess:

  <Directory /var/www/foo/site>
   AddHandler python-program .py
   PythonHandler mod_python.publisher
   PythonDebug On
   # set headers to prevent caching for anything in this directory
   Header set Pragma "no-cache"
   Header set Cache-Control "no-cache"
   Header set Expires "-1"

Note: I use the somewhat outdated versions of apache and mod_python that 
come with Debian Woody, so be sure to check for the correct syntax for 
your versions. You might need to add the correct apache module to get 
the Header directives to work in httpd.conf.

More information about the Mod_python mailing list