CC: | Yanick Champoux <yanick [...] babyl.dyndns.org> |
Subject: | [PATCH] change finalize for after 'dispatch' |
Date: | Sun, 6 Mar 2011 00:24:22 -0500 |
To: | bug-Catalyst-Plugin-PageCache [...] rt.cpan.org |
From: | Yanick Champoux <yanick [...] babyl.dyndns.org> |
C::P::PC doesn't seem to play well with Catalyst::Plugin::SubRequest.
From what I can see, it's because only the main request, and not the
subrequests, hit 'finalize' and get cached.
To get around this problem, I've swapper the 'finalize' method
for a Moosish 'after dispatch => sub {...'. The tests are
still passing, and it seems to do the trick, but I'd recommend
to carefully review my patch, as I don't know enough of C::P::PC's
guts to know if what I did won't bite us back in some special
scenario.
---
lib/Catalyst/Plugin/PageCache.pm | 15 ++++++++-------
1 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/lib/Catalyst/Plugin/PageCache.pm b/lib/Catalyst/Plugin/PageCache.pm
index 0444b44..65a1357 100644
--- a/lib/Catalyst/Plugin/PageCache.pm
+++ b/lib/Catalyst/Plugin/PageCache.pm
@@ -5,6 +5,8 @@ use base qw/Class::Accessor::Fast/;
use MRO::Compat;
use Digest::SHA1 ();
+use Moose;
+
our $VERSION = '0.31';
# Do we need to cache the current page?
@@ -261,27 +263,27 @@ sub _set_page_cache_headers {
unless $c->res->status && $c->res->status == 304;
}
-sub finalize {
+after dispatch => sub {
my $c = shift;
# never cache POST requests
- return $c->next::method(@_) if ( $c->req->method eq "POST" );
+ return if ( $c->req->method eq "POST" );
my $pc_config = $c->config->{'Plugin::PageCache'};
my $hook_name = $pc_config->{cache_dispatch_hook} || $pc_config->{cache_hook};
my $hook = $hook_name ? $c->can($hook_name) : undef;
- return $c->next::method(@_) if ( $hook && !$c->$hook() );
+ return if ( $hook && !$c->$hook() );
return $c->next::method(@_)
if ( $pc_config->{auto_check_user}
&& $c->can('user_exists')
&& $c->user_exists);
- return $c->next::method(@_) if ( scalar @{ $c->error } );
+ return if ( scalar @{ $c->error } );
# if we already served the current request from cache, we can skip the
# rest of this method
- return $c->next::method(@_) if ( $c->_page_cache_used );
+ return if ( $c->_page_cache_used );
if (!$c->_cache_page
&& scalar @{ $pc_config->{auto_cache} })
@@ -311,8 +313,7 @@ sub finalize {
$c->_page_cache_not_modified( $data ) if $data;
}
- return $c->next::method(@_);
-}
+};
sub _store_page_in_cache {
--
1.7.3.4