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

andyg at dev.catalyst.perl.org andyg at dev.catalyst.perl.org
Tue Sep 30 00:21:20 BST 2008


Author: andyg
Date: 2008-09-30 00:21:20 +0100 (Tue, 30 Sep 2008)
New Revision: 8478

Modified:
   trunk/Catalyst-Plugin-PageCache/Changes
   trunk/Catalyst-Plugin-PageCache/README
   trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm
Log:
Add disable_index option to improve performance by not storing the cache index

Modified: trunk/Catalyst-Plugin-PageCache/Changes
===================================================================
--- trunk/Catalyst-Plugin-PageCache/Changes	2008-09-29 22:47:29 UTC (rev 8477)
+++ trunk/Catalyst-Plugin-PageCache/Changes	2008-09-29 23:21:20 UTC (rev 8478)
@@ -3,6 +3,8 @@
 0.20    
         - Config option 'cache_headers' to cache HTTP headers.  This is needed
           if operating behind edge caches such as Akamai. (Chris Alef)
+        - The ability to call clear_cached_page can be disabled to improve
+          performance (a cache index will not be created/updated).
         
 0.19    2008-08-22 13:00:00
         - Change config namespace to $c->config->{'Plugin::PageCache'}, old

Modified: trunk/Catalyst-Plugin-PageCache/README
===================================================================
--- trunk/Catalyst-Plugin-PageCache/README	2008-09-29 22:47:29 UTC (rev 8477)
+++ trunk/Catalyst-Plugin-PageCache/README	2008-09-29 23:21:20 UTC (rev 8478)
@@ -80,6 +80,12 @@
     This will set the default expiration time for all page caches. If you do
     not specify this, expiration defaults to 300 seconds (5 minutes).
 
+        cache_headers => 1
+
+    Enable this value if you need your cached responses to include custom
+    HTTP headers set by your application. This may be necessary if you
+    operate behind an edge cache such as Akamai.
+
         set_http_headers => 1
 
     Enabling this value will cause Catalyst to set the correct HTTP headers
@@ -161,7 +167,7 @@
     The page will be stored in the page cache until this time.
 
     If set_http_headers is set then Expires and Cache-Control headers will
-    also be set to expire at the given date as well
+    also be set to expire at the given date as well.
 
     Pass in a list or hash reference for finer control.
 
@@ -199,41 +205,6 @@
         Allows caching expensive content to generate, but any changes will
         be seen right away.
 
-    To make the cache expire at a given point in time, pass in a DateTime
-    object.
-
-        $two_hours = DateTime->now->add( hours => 2 );
-        $c->cache_page( $two_hours );
-
-    If set_http_headers is set then Expires and Cache-Control headers will
-    be set to expire at the given date.
-
-    Pass in a list or hash reference for finer control.
-
-        $c->cache_page(
-            last_modified   => $last_modified,
-            cache_seconds   => 24 * 60 * 60,
-            expires         => 30,
-        );
-
-    Possible options are:
-
-    last_modified
-        Last modified time in epoch seconds. If not set will use either the
-        current Last-Modified header or the current time.
-
-    cache_seconds
-        This is the number of seconds to keep the page in the page cache,
-        which may be different (normally longer) then the time that client
-        caches may use the page.
-
-    expires
-        This is the lenght of time in seconds that a client may cache the
-        page before revalidating (by asking the server if the document has
-        changed).
-
-        Unlike the "expires" setting above
-
   clear_cached_page
     To clear the cached value for a URI, you may call clear_cached_page.
 
@@ -245,6 +216,9 @@
     controller. You may for example wish to build an admin page that lets
     you clear page caches.
 
+    Note that clear_cached_page will generate a warning if disable_index is
+    enabled.
+
 INTERNAL EXTENDED METHODS
   dispatch
     "dispatch" decides whether or not to serve a particular request from the

Modified: trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm
===================================================================
--- trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm	2008-09-29 22:47:29 UTC (rev 8477)
+++ trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm	2008-09-29 23:21:20 UTC (rev 8478)
@@ -50,10 +50,16 @@
 
     return unless ( $c->can( 'cache' ) );
     
+    # Warn if index was disabled
+    if ( $c->config->{'Plugin::PageCache'}->{disable_index} ) {
+        $c->log->warn("Warning: clear_cached_page($uri) did not clear the cache, disable_index is set");
+        return;
+    }
+    
     my $is_debug = $c->config->{'Plugin::PageCache'}->{debug};
 
     my $removed = 0;
-
+    
     my $index = $c->cache->get( "_page_cache_index" ) || {};
 
     foreach my $key ( keys %{$index} ) {
@@ -61,11 +67,11 @@
             $c->cache->remove( $key );
             delete $index->{$key};
             $removed++;
-            
+        
             $c->log->debug( "Removed $key from page cache" ) if $is_debug;
         }
     }
-    
+
     if ( $removed ) {
         $c->cache->set(
             "_page_cache_index",
@@ -108,10 +114,12 @@
 
         $c->cache->remove( $key );
 
-        my $index = $c->cache->get( "_page_cache_index" ) || {};
-        delete $index->{$key};
-        $c->cache->set( "_page_cache_index", $index,
-            $c->config->{'Plugin::PageCache'}->{no_expire});
+        if ( !$c->config->{'Plugin::PageCache'}->{disable_index} ) {
+            my $index = $c->cache->get( "_page_cache_index" ) || {};
+            delete $index->{$key};
+            $c->cache->set( "_page_cache_index", $index,
+                $c->config->{'Plugin::PageCache'}->{no_expire});
+        }
 
         return $c->NEXT::dispatch(@_);
     }
@@ -281,16 +289,17 @@
 
         $c->_set_page_cache_headers( $data );  # don't forget the first time
 
-        # Keep an index cache of all pages that have been cached, for use
-        # with clear_cached_page
+        if ( !$c->config->{'Plugin::PageCache'}->{disable_index} ) {
+            # Keep an index cache of all pages that have been cached, for use
+            # with clear_cached_page
+            my $index = $c->cache->get( "_page_cache_index" ) || {};
+            $index->{$key} = 1;
 
-        my $index = $c->cache->get( "_page_cache_index" ) || {};
-        $index->{$key} = 1;
+            # Save date in cache
+            $c->cache->set( "_page_cache_index", $index,
+                $c->config->{'Plugin::PageCache'}->{no_expire});
+        }
 
-        # Save date in cache
-        $c->cache->set( "_page_cache_index", $index,
-            $c->config->{'Plugin::PageCache'}->{no_expire});
-
         # Check for If-Modified-Since
         $c->_page_cache_not_modified( $data );
     }
@@ -312,6 +321,7 @@
     $c->config->{'Plugin::PageCache'}->{expires}          ||= 60 * 5;
     $c->config->{'Plugin::PageCache'}->{cache_headers}    ||= 0;
     $c->config->{'Plugin::PageCache'}->{set_http_headers} ||= 0;
+    $c->config->{'Plugin::PageCache'}->{disable_index}    ||= 0;
     $c->config->{'Plugin::PageCache'}->{debug}            ||= $c->debug;
 
     # detect the cache plugin being used and set appropriate
@@ -491,6 +501,13 @@
 matches one of the auto_cache URIs will be cached using the default expiration
 time.  URIs may be specified as absolute: '/list' or as a regex: '/view/.*'
 
+    disable_index => 1
+
+In order to support the C<clear_cached_page> method, PageCache keeps an index of
+all cached pages.  If you don't intend to use C<clear_cached_page>, you may 
+enable this config option to avoid the overhead of creating and updating the
+cache index.
+
     debug => 1
 
 This will print additional debugging information to the Catalyst log.  You will
@@ -554,7 +571,7 @@
 The page will be stored in the page cache until this time.
 
 If set_http_headers is set then Expires and Cache-Control headers will
-also be set to expire at the given date as well
+also be set to expire at the given date as well.
 
 Pass in a list or hash reference for finer control.
 
@@ -594,53 +611,8 @@
 will be sent telling the client to not cache the page.  Allows caching expensive
 content to generate, but any changes will be seen right away.
 
-
-
 =back
 
-
-To make the cache expire at a given point in time, pass in a DateTime object.
-
-    $two_hours = DateTime->now->add( hours => 2 );
-    $c->cache_page( $two_hours );
-
-If set_http_headers is set then Expires and Cache-Control headers will
-be set to expire at the given date.
-
-Pass in a list or hash reference for finer control.
-
-    $c->cache_page(
-        last_modified   => $last_modified,
-        cache_seconds   => 24 * 60 * 60,
-        expires         => 30,
-    );
-
-Possible options are:
-
-=over 4
-
-=item last_modified
-
-Last modified time in epoch seconds.  If not set will use either the
-current Last-Modified header or the current time.
-
-=item cache_seconds
-
-This is the number of seconds to keep the page in the page cache, which may be 
-different (normally longer) then the time that client caches may use the page.
-
-=item expires
-
-This is the lenght of time in seconds that a client may cache the page
-before revalidating (by asking the server if the document has changed).
-
-Unlike the "expires" setting above
-
-
-
-=back
-
-
 =head2 clear_cached_page
 
 To clear the cached value for a URI, you may call clear_cached_page.
@@ -652,6 +624,8 @@
 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.
 
+Note that clear_cached_page will generate a warning if disable_index is enabled.
+
 =head1 INTERNAL EXTENDED METHODS
 
 =head2 dispatch




More information about the Catalyst-commits mailing list