http://qs321.pair.com?node_id=239698

This is really more of a HTTP- than Perl-related post; the following snippet emits all of the currently specified HTTP headers that may affect caching, with values set to coerce clients into not caching the document in question. It’s useful for debugging as well as generated pages that actually are very dynamic, but shouldn’t be used blindly for everything – caching is there for a reason.

(I’m posting this here mainly so as to have a node to refer people to as needed.)

Update 2006-01-12: added private and max-age=0 to the Cache-Control header.

use CGI qw(:standard); use POSIX qw(strftime); print header( # date in the past -expires => 'Sat, 26 Jul 1997 05:00:00 GMT', # always modified -Last_Modified => strftime('%a, %d %b %Y %H:%M:%S GMT', gmtime), # HTTP/1.0 -Pragma => 'no-cache', # HTTP/1.1 + IE-specific (pre|post)-check -Cache_Control => join(', ', qw( private no-cache no-store must-revalidate max-age=0 pre-check=0 post-check=0 )), );