[Catalyst] Caching problem?

Jesse Sheidlower jester at panix.com
Wed Jan 11 20:43:23 CET 2006


On Wed, Jan 11, 2006 at 11:59:42AM -0500, Andy Grundman wrote:
> Dr. Jennifer Nussbaum wrote:
> > hi,
> >
> >I have a Catalyst application that does the usual database thingies. I
> >just learned that when database info changes, the pages arent getting
> >updated because theyre being cached, so if someone goes to
> >www.mysite.com/catalog/view/242, they get the same content even if
> >things have changed. Users can "reload" in the browser and get the
> >right content.
> >
> >Whats the easiest way that this doesnt happen?
> 
> You probably want to set a Cache-Control header.  This is a good page to 
> read about the topic: http://www.mnot.net/cache_docs/
> 
> A simple no-cache setup in Catalyst would look like this, in your end 
> method:
> 
> $c->res->headers->header( 'Cache-Control' => 'no-cache, max-age=0' );

Apart from the more extended headers that others have talked about, I've
also found it sensible to turn this into something like:

  $c->res->headers->header( 'Cache-Control' => 'no-cache, max-age=0' )
     unless $c->req->path =~ /static/;

so that your static content (images, CSS files, JS) can be
cached. This depends on your storing such content in a /static
directory, etc., but it works for me.

Jesse Sheidlower



More information about the Catalyst mailing list