[Catalyst-commits] r7634 - trunk/Catalyst-Plugin-PageCache

andyg at dev.catalyst.perl.org andyg at dev.catalyst.perl.org
Fri Apr 25 16:20:47 BST 2008


Author: andyg
Date: 2008-04-25 16:20:47 +0100 (Fri, 25 Apr 2008)
New Revision: 7634

Modified:
   trunk/Catalyst-Plugin-PageCache/Changes
   trunk/Catalyst-Plugin-PageCache/README
Log:
PageCache 0.18

Modified: trunk/Catalyst-Plugin-PageCache/Changes
===================================================================
--- trunk/Catalyst-Plugin-PageCache/Changes	2008-04-25 15:15:49 UTC (rev 7633)
+++ trunk/Catalyst-Plugin-PageCache/Changes	2008-04-25 15:20:47 UTC (rev 7634)
@@ -1,6 +1,6 @@
 Revision history for Perl extension Catalyst::Plugin::PageCache
 
-0.18
+0.18    2008-04-25 11:30:00
         - cache_hook method, run a method before returning a cached page.
           (J. Shirley)
 

Modified: trunk/Catalyst-Plugin-PageCache/README
===================================================================
--- trunk/Catalyst-Plugin-PageCache/README	2008-04-25 15:15:49 UTC (rev 7633)
+++ trunk/Catalyst-Plugin-PageCache/README	2008-04-25 15:20:47 UTC (rev 7634)
@@ -13,16 +13,30 @@
                 '/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'
         };
+        
+    sub some_method {
+            my ( $c ) = @_;
+            if ( $c->user_exists and $c->user->some_field ) {
+                return 0; # Don't cache
+            }
+            return 1; # Cache
+        }
 
         # in a controller method
         $c->cache_page( '3600' );
 
         $c->clear_cached_page( '/list' );
 
+
         # Expire at a specific time
         $c->cache_page( $datetime_object );
 
+
         # Fine control
         $c->cache_page(
             last_modified   => $last_modified,
@@ -90,6 +104,29 @@
     specify an optional config parameter auto_check_user. If this option is
     enabled, automatic caching is disabled for logged in users.
 
+        cache_hook => 'cache_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 circuit the pagecache behavior. As an example, if you want to
+    disable PageCache while running under debug mode:
+
+        package MyApp;
+        
+    ...
+        
+    sub cache_hook_method { return shift->debug; }
+
+    Or, if you want to not cache for certain roles, say "admin":
+
+        sub cache_hook_method {
+            my ( $c ) = @_;
+            return !$c->check_user_roles('admin');
+        }
+
+    Note that this is called BEFORE auto_check_user, so you have more
+    flexibility to determine what to do for not logged in users.
+
 METHODS
   cache_page
     Call cache_page in any controller method you wish to be cached.
@@ -206,6 +243,11 @@
   setup
     "setup" initializes all default values.
 
+I18N SUPPORT
+    If your application uses Catalyst::Plugin::I18N for localization, a
+    separate cache key will be used for each language a page is displayed
+    in.
+
 KNOWN ISSUES
     It is not currently possible to cache pages served from the Static
     plugin. If you're concerned enough about performance to use this plugin,
@@ -228,6 +270,8 @@
 THANKS
     Bill Moseley, <mods at hank.org>, for many patches and tests.
 
+    Roberto HenrÃquez, <roberto at freekeylabs.com>, for i18n support.
+
 COPYRIGHT
     This program is free software, you can redistribute it and/or modify it
     under the same terms as Perl itself.




More information about the Catalyst-commits mailing list