Skip Menu |

This queue is for tickets about the Catalyst-Plugin-PageCache CPAN distribution.

Report information
The Basics
Id: 53503
Status: open
Priority: 0/
Queue: Catalyst-Plugin-PageCache

People
Owner: Nobody in particular
Requestors: rod.taylor [...] gmail.com
Cc: cpan.org [...] mavit.org.uk
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.31
Fixed in: (no value)



Subject: Allow different hooks for dispatch and finalize
Allow different hooks for dispatch and finalize. It allows for complex logic such as always displaying/generating a fresh page for a specific IP address; and caching the result.

By default it copies the cache_hook method to cache_finalize_hook and cache_dispatch_hook if they are not set. I tried doing this in setup() but that didn't work if the AppConfig is in a Controller file, as is the case with the test files.

Subject: hooks.patch
*** Catalyst-Plugin-PageCache_WRITE/lib/Catalyst/Plugin/PageCache.pm 2010-01-02 20:39:49.000000000 -0500 --- Catalyst-Plugin-PageCache_HOOKS/lib/Catalyst/Plugin/PageCache.pm 2010-01-07 22:23:47.000000000 -0500 *************** *** 155,163 **** # never serve POST, PUT, DELETE, ... request pages from cache. GET/HEAD only return $c->next::method(@_) unless ( $c->req->method eq 'GET' or $c->req->method eq 'HEAD' ); my $hook = ! $c->config->{'Plugin::PageCache'}->{cache_hook} ! ? $c->can($c->config->{'Plugin::PageCache'}->{cache_hook}) : undef; return $c->next::method(@_) if ( $hook && !$c->$hook() ); --- 155,164 ---- # never serve POST, PUT, DELETE, ... request pages from cache. GET/HEAD only return $c->next::method(@_) unless ( $c->req->method eq 'GET' or $c->req->method eq 'HEAD' ); + $c->config->{'Plugin::PageCache'}->{cache_dispatch_hook} ||= $c->config->{'Plugin::PageCache'}->{cache_hook}; my $hook = ! $c->config->{'Plugin::PageCache'}->{cache_dispatch_hook} ! ? $c->can($c->config->{'Plugin::PageCache'}->{cache_dispatch_hook}) : undef; return $c->next::method(@_) if ( $hook && !$c->$hook() ); *************** *** 298,306 **** # never cache POST requests return $c->next::method(@_) if ( $c->req->method eq "POST" ); my $hook = ! $c->config->{'Plugin::PageCache'}->{cache_hook} ! ? $c->can($c->config->{'Plugin::PageCache'}->{cache_hook}) : undef; return $c->next::method(@_) if ( $hook && !$c->$hook() ); --- 299,308 ---- # never cache POST requests return $c->next::method(@_) if ( $c->req->method eq "POST" ); + $c->config->{'Plugin::PageCache'}->{cache_finalize_hook} ||= $c->config->{'Plugin::PageCache'}->{cache_hook}; my $hook = ! $c->config->{'Plugin::PageCache'}->{cache_finalize_hook} ! ? $c->can($c->config->{'Plugin::PageCache'}->{cache_finalize_hook}) : undef; return $c->next::method(@_) if ( $hook && !$c->$hook() ); *************** *** 492,501 **** '/list', ], debug => 1, # Optionally, a cache hook to be called prior to dispatch to # determine if the page should be cached. This is called both # before dispatch, and before finalize. ! cache_hook => 'some_method' } ); --- 494,512 ---- '/list', ], debug => 1, + # Optionally, a cache hook to be called prior to dispatch to # determine if the page should be cached. This is called both # before dispatch, and before finalize. ! cache_hook => 'some_method', ! ! # You may alternatively set different methods to be used as hooks ! # for dispatch and finalize. The dispatch method will determine ! # whether the currently cached page will be displayed to the user, ! # and the finalize hook will determine whether to save the newly ! # created page. ! cache_dispatch_hook => 'some_method_for_dispatch', ! cache_finalize_hook => 'some_method_for_finalize', } ); *************** *** 614,619 **** --- 625,632 ---- automatic caching is disabled for logged in users. cache_hook => 'cache_hook_method' + cache_finalize_hook => 'cache_finalize_hook_method' + cache_dispatch_hook => 'cache_dispatch_hook_method' Calls a method on the application that is expected to return a true or false. This method is called before dispatch, and before finalize so you can short *************** *** 647,652 **** --- 660,676 ---- } ); + In most cases you would use a single cache_hook method for consistency. + + It is possible to achieve background refreshing of content by disabling + caching in cache_dispatch_hook and enabling caching in cache_finalize_hook + for a specific IP address (say 127.0.0.1). + + A cron of wget "http://localhost/foo.html" would cause the content to be + generated fresh and cached for future viewers. Useful for content which + takes a very long time to build or pages which should be refreshed at + a specific time such as always rolling over content at midnight. + =head1 METHODS =head2 cache_page
Applied. Thanks!
Something seems to have gone awry when this patch was applied. In 0.31, cache_dispatch_hook is used both in the dispatch and finalize methods. The cache_finalize_hook is never called.