[Catalyst-commits] r13672 - in trunk/Catalyst-Plugin-PageCache: . lib/Catalyst/Plugin

timbunce at dev.catalyst.perl.org timbunce at dev.catalyst.perl.org
Mon Nov 1 12:33:15 GMT 2010


Author: timbunce
Date: 2010-11-01 12:33:15 +0000 (Mon, 01 Nov 2010)
New Revision: 13672

Modified:
   trunk/Catalyst-Plugin-PageCache/Changes
   trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm
Log:
Add cache_dispatch_hook and cache_finalize_hook to config. RT#53503

Modified: trunk/Catalyst-Plugin-PageCache/Changes
===================================================================
--- trunk/Catalyst-Plugin-PageCache/Changes	2010-11-01 12:18:33 UTC (rev 13671)
+++ trunk/Catalyst-Plugin-PageCache/Changes	2010-11-01 12:33:15 UTC (rev 13672)
@@ -9,6 +9,7 @@
         - Only serve GET and HEAD requests (instead of all except POST). RT#53307.
         - Allow key_maker to be the name of a method to be called on $c. RT#53529.
         - Assorted performance optimizations.
+        - Add cache_dispatch_hook and cache_finalize_hook to config. RT#53503.
 
 0.22    2009-06-25 10:38:00
         - Update to use MRO::Compat

Modified: trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm
===================================================================
--- trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm	2010-11-01 12:18:33 UTC (rev 13671)
+++ trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm	2010-11-01 12:33:15 UTC (rev 13672)
@@ -95,12 +95,9 @@
 
     my $config_PageCache = $c->config->{'Plugin::PageCache'};
 
-    my $hook =
-        $config_PageCache->{cache_hook}
-      ? $c->can($config_PageCache->{cache_hook})
-      : undef;
-    
-    return $c->next::method(@_) if ( $hook && !$c->$hook() );
+    my $hook_name = $config_PageCache->{cache_dispatch_hook} || $config_PageCache->{cache_hook};
+    return $c->next::method(@_)
+        if $hook_name && $c->can($hook_name) && not $c->$hook();
 
     return $c->next::method(@_)
       if ( $config_PageCache->{auto_check_user}
@@ -244,11 +241,9 @@
 
     my $config_PageCache = $c->config->{'Plugin::PageCache'};
 
-    my $hook =
-        $config_PageCache->{cache_hook}
-      ? $c->can($config_PageCache->{cache_hook})
-      : undef;
-    return $c->next::method(@_) if ( $hook && !$c->$hook() );
+    my $hook_name = $config_PageCache->{cache_dispatch_hook} || $config_PageCache->{cache_hook};
+    return $c->next::method(@_)
+        if $hook_name && $c->can($hook_name) && not $c->$hook();
 
     return $c->next::method(@_)
       if ( $config_PageCache->{auto_check_user}
@@ -444,10 +439,19 @@
                 '/list',
             ],
             debug => 1,
-            # Optionally, a cache hook to be called prior to dispatch to
+
+            # Optionally, a cache hook method 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'
+            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',
         }
     );
     
@@ -563,6 +567,8 @@
 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
@@ -598,6 +604,17 @@
 
 C<key_maker> can also be the name of a method, which will be invoked as C<<$c->$key_maker>>.
 
+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




More information about the Catalyst-commits mailing list