[Catalyst] exempt special pages from caching with Catalyst::Plugin::PageCache

Matthias Zeichmann matthias at volltext.net
Wed Aug 30 14:47:49 CEST 2006


hey list,

actually not a question but a how to, kd on #catalyst asked me to post
(he also suggested to ask for someone with access to put it on the
SolvedIssues part of the wiki)

what i want to do is cache all pages for an app except of pages ending
in /debug and /expire

this is accomplished with

MyApp/lib/MyApp.pm
---------->8-----------------------------------------------------
__PACKAGE__->config->{page_cache} = {
    expires => 60,
    auto_cache => [
        '(?!.*/(debug|expire)\z).*',
    ],  # cache everything but requests ending in /(debug|expire)
};
---------->8-----------------------------------------------------

while in MyApp/lib/MyApp/Controller/Root.pm i got
---------->8-----------------------------------------------------
sub begin : Private {
    my ( $self, $c ) = @_;

    if ($c->config->{page_cache} && $c->req->path =~ m#(.*)/expire$#) {
        $c->clear_cached_page( '/' . $1 );
    } 
}
---------->8-----------------------------------------------------

so actually you can call clear_cached_page from the cached controller in
contrast to what the manpage says:
---------->8-----------------------------------------------------
       clear_cached_page

       [...]                                                 For obvious
       reasons, this must be called from a different controller than the
       cached controller. You may for example wish to build an admin  
       page that lets you clear page caches.
---------->8-----------------------------------------------------

kudos for mauke at #perl for help with the negative lookahead :D




More information about the Catalyst mailing list