[Catalyst] Opinions on static::simple - with caching

Toby Corkindale toby at dryft.net
Mon Jan 31 07:17:42 GMT 2011

I'm wondering if the following plugin I've written is misguided..
It enables proxy caches and browsers to better cache the files served
by Static::Simple..
However, I suppose in situations where that matters, you shouldn't be
serving files via Static::Simple..
And the regular Static::Simple still provides Last-Modified headers,
which do allow browsers to perform some caching.

What do you think?

To enable this plugin, you need:

  use Catalyst qw(

package Catalyst::Plugin::Static::Caching;
use Moose::Role;
requires '_serve_static'; # From Catalyst::Plugin::Static::Simple

after _serve_static => sub {
    my $c = shift;
    # Avoid setting an expires if the parent never found the file..
    return unless (defined $c->response->body
        and ref($c->response->body) eq 'IO::File');

    # Tell browsers they can cache files for a couple of hours:
    $c->res->headers->expires(time() + 7200);
    # Tell Firefox it's OK to cache, even over SSL:
    $c->res->headers->header('Cache-control' => 'public');


More information about the Catalyst mailing list