[Catalyst-commits] r8259 - in tags/Catalyst-Plugin-PageCache: .
0.19 0.19/lib/Catalyst/Plugin 0.19/t
andyg at dev.catalyst.perl.org
andyg at dev.catalyst.perl.org
Fri Aug 22 18:00:39 BST 2008
Author: andyg
Date: 2008-08-22 18:00:39 +0100 (Fri, 22 Aug 2008)
New Revision: 8259
Added:
tags/Catalyst-Plugin-PageCache/0.19/
tags/Catalyst-Plugin-PageCache/0.19/Changes
tags/Catalyst-Plugin-PageCache/0.19/README
tags/Catalyst-Plugin-PageCache/0.19/TODO
tags/Catalyst-Plugin-PageCache/0.19/lib/Catalyst/Plugin/PageCache.pm
tags/Catalyst-Plugin-PageCache/0.19/t/05expires.t
tags/Catalyst-Plugin-PageCache/0.19/t/06auto_cache.t
tags/Catalyst-Plugin-PageCache/0.19/t/07set_http_headers.t
tags/Catalyst-Plugin-PageCache/0.19/t/09datetime.t
tags/Catalyst-Plugin-PageCache/0.19/t/10options.t
tags/Catalyst-Plugin-PageCache/0.19/t/11nocache.t
tags/Catalyst-Plugin-PageCache/0.19/t/13cachehook.t
tags/Catalyst-Plugin-PageCache/0.19/t/14keymaker.t
Removed:
tags/Catalyst-Plugin-PageCache/0.19/Changes
tags/Catalyst-Plugin-PageCache/0.19/README
tags/Catalyst-Plugin-PageCache/0.19/lib/Catalyst/Plugin/PageCache.pm
tags/Catalyst-Plugin-PageCache/0.19/t/05expires.t
tags/Catalyst-Plugin-PageCache/0.19/t/06auto_cache.t
tags/Catalyst-Plugin-PageCache/0.19/t/07set_http_headers.t
tags/Catalyst-Plugin-PageCache/0.19/t/09datetime.t
tags/Catalyst-Plugin-PageCache/0.19/t/10options.t
tags/Catalyst-Plugin-PageCache/0.19/t/11nocache.t
tags/Catalyst-Plugin-PageCache/0.19/t/13cachehook.t
Log:
Tagging 0.19
Copied: tags/Catalyst-Plugin-PageCache/0.19 (from rev 8250, trunk/Catalyst-Plugin-PageCache)
Deleted: tags/Catalyst-Plugin-PageCache/0.19/Changes
===================================================================
--- trunk/Catalyst-Plugin-PageCache/Changes 2008-08-21 19:46:02 UTC (rev 8250)
+++ tags/Catalyst-Plugin-PageCache/0.19/Changes 2008-08-22 17:00:39 UTC (rev 8259)
@@ -1,92 +0,0 @@
-Revision history for Perl extension Catalyst::Plugin::PageCache
-
-0.18 2008-04-25 11:30:00
- - cache_hook method, run a method before returning a cached page.
- (J. Shirley)
-
-0.17 2007-07-29 22:00:00
- - If using C::P::I18N, allow caching of different versions of a
- single URI based on the page language. (Roberto HenrÃquez)
-
-0.16 2007-07-24 10:30:00
- - Fixed a bug where pages with query strings but no params
- did not have the cache key created properly.
- - Switched to Module::Install.
-
-0.15 2006-12-31 20:04:03
- - Don't cache pages with errors.
-
-0.14 2006-10-19 22:15:00
- - Support newer C::P::Cache modules.
-
-0.13 2006-08-12 14:43:00
- - Add optional support to check Authentication plugin if user is
- logged in. (marcus)
-
-0.12 2006-03-09 16:30:00
- - Fixed race condition in HTTP header test.
- - Fixed Content-type to retain charset (moseley)
- - Send cache headers on all requests (was not sending on first
- request) (moseley)
- - Added ability to pass in a DateTime object to expire at a specific
- time (moseley)
- - Added ability to pass in an options list to set the cache expires
- time separately from the expires time sent to client. (moseley)
- - Test If-Modified-Since headers on request that loads the page cache.
- Was only testing when returning a page already in the page cache.
- (moseley)
- - Now sends Expires and Cache-Control headers on 304 to reset client cache.
- (moseley)
- - Allow setting a zero expires to allow just page caching. (moseley)
-
-0.11 2005-09-13 14:50:00
- - Fixed MANIFEST.
-
-0.10 2005-09-13 14:00:00
- - Fixed bug in cache key generation that ignored duplicate key names.
- - Fixed bug where clear_cached_page called with a regex did not
- properly remove the page from cache.
- - Fixed bug where cache metadata was not set properly if
- content-type or content-encoding was missing.
- - Added test suite.
- - Code cleanup per Best Practices.
-
-0.09 2005-06-27 11:25:00
- - Removed dependence on HTTP::Date.
- - Make sure the same cache key checked during the dispatch phase
- is used during the finalize phase. This avoids problems if the
- user adds or deletes request parameters.
-
-0.08 2005-06-16 00:20:00
- - Debug is now enabled by default if in Catalyst -Debug mode.
- - Expires now properly defaults to undef for Cache::Memcached backend.
-
-0.07 2005-06-13 23:15:00
- - Bugfix: Define auto_cache to an empty arrayref if not specified.
-
-0.06 2005-06-07 23:40:00
- - Die if no cache plugin is loaded. (chansen)
- - Changed to isa() for cache backend detection. (chansen)
-
-0.05 2005-06-06 23:15:00
- - Fixed bug in clear_cached_page when cache index is not
- available.
- - Added cache backend detection in order to properly keep the
- cache index from expiring when possible.
- - Remove page from cache index when it has expired.
-
-0.04 2005-06-05 16:20:00
- - Removed unnecessary prepare_request method.
-
-0.03 2005-06-04 22:30:00
- - Switched to Class::Accessor::Fast. (chansen)
- - Preserve Last-Modified time of the cached data. (chansen)
-
-0.02 2005-06-04 18:13:00
- - Preserve Content-Type and Content-Encoding of cached data. (chansen)
- - Send 304 Not Modified header when a browser or proxy requests
- If-Modified-Since and the data is still cached. (chansen)
- - Don't check the auto list if the page will already be cached.
-
-0.01 2005-06-04 12:00:00
- - initial release
Copied: tags/Catalyst-Plugin-PageCache/0.19/Changes (from rev 8258, trunk/Catalyst-Plugin-PageCache/Changes)
===================================================================
--- tags/Catalyst-Plugin-PageCache/0.19/Changes (rev 0)
+++ tags/Catalyst-Plugin-PageCache/0.19/Changes 2008-08-22 17:00:39 UTC (rev 8259)
@@ -0,0 +1,97 @@
+Revision history for Perl extension Catalyst::Plugin::PageCache
+
+0.19 2008-08-22 13:00:00
+ - Change config namespace to $c->config->{'Plugin::PageCache'}, old namespace will
+ still continue to work.
+ - key_maker method, allows custom cache keys to be used. (Martin Ellison)
+
+0.18 2008-04-25 11:30:00
+ - cache_hook method, run a method before returning a cached page.
+ (J. Shirley)
+
+0.17 2007-07-29 22:00:00
+ - If using C::P::I18N, allow caching of different versions of a
+ single URI based on the page language. (Roberto HenrÃquez)
+
+0.16 2007-07-24 10:30:00
+ - Fixed a bug where pages with query strings but no params
+ did not have the cache key created properly.
+ - Switched to Module::Install.
+
+0.15 2006-12-31 20:04:03
+ - Don't cache pages with errors.
+
+0.14 2006-10-19 22:15:00
+ - Support newer C::P::Cache modules.
+
+0.13 2006-08-12 14:43:00
+ - Add optional support to check Authentication plugin if user is
+ logged in. (marcus)
+
+0.12 2006-03-09 16:30:00
+ - Fixed race condition in HTTP header test.
+ - Fixed Content-type to retain charset (moseley)
+ - Send cache headers on all requests (was not sending on first
+ request) (moseley)
+ - Added ability to pass in a DateTime object to expire at a specific
+ time (moseley)
+ - Added ability to pass in an options list to set the cache expires
+ time separately from the expires time sent to client. (moseley)
+ - Test If-Modified-Since headers on request that loads the page cache.
+ Was only testing when returning a page already in the page cache.
+ (moseley)
+ - Now sends Expires and Cache-Control headers on 304 to reset client cache.
+ (moseley)
+ - Allow setting a zero expires to allow just page caching. (moseley)
+
+0.11 2005-09-13 14:50:00
+ - Fixed MANIFEST.
+
+0.10 2005-09-13 14:00:00
+ - Fixed bug in cache key generation that ignored duplicate key names.
+ - Fixed bug where clear_cached_page called with a regex did not
+ properly remove the page from cache.
+ - Fixed bug where cache metadata was not set properly if
+ content-type or content-encoding was missing.
+ - Added test suite.
+ - Code cleanup per Best Practices.
+
+0.09 2005-06-27 11:25:00
+ - Removed dependence on HTTP::Date.
+ - Make sure the same cache key checked during the dispatch phase
+ is used during the finalize phase. This avoids problems if the
+ user adds or deletes request parameters.
+
+0.08 2005-06-16 00:20:00
+ - Debug is now enabled by default if in Catalyst -Debug mode.
+ - Expires now properly defaults to undef for Cache::Memcached backend.
+
+0.07 2005-06-13 23:15:00
+ - Bugfix: Define auto_cache to an empty arrayref if not specified.
+
+0.06 2005-06-07 23:40:00
+ - Die if no cache plugin is loaded. (chansen)
+ - Changed to isa() for cache backend detection. (chansen)
+
+0.05 2005-06-06 23:15:00
+ - Fixed bug in clear_cached_page when cache index is not
+ available.
+ - Added cache backend detection in order to properly keep the
+ cache index from expiring when possible.
+ - Remove page from cache index when it has expired.
+
+0.04 2005-06-05 16:20:00
+ - Removed unnecessary prepare_request method.
+
+0.03 2005-06-04 22:30:00
+ - Switched to Class::Accessor::Fast. (chansen)
+ - Preserve Last-Modified time of the cached data. (chansen)
+
+0.02 2005-06-04 18:13:00
+ - Preserve Content-Type and Content-Encoding of cached data. (chansen)
+ - Send 304 Not Modified header when a browser or proxy requests
+ If-Modified-Since and the data is still cached. (chansen)
+ - Don't check the auto list if the page will already be cached.
+
+0.01 2005-06-04 12:00:00
+ - initial release
Deleted: tags/Catalyst-Plugin-PageCache/0.19/README
===================================================================
--- trunk/Catalyst-Plugin-PageCache/README 2008-08-21 19:46:02 UTC (rev 8250)
+++ tags/Catalyst-Plugin-PageCache/0.19/README 2008-08-22 17:00:39 UTC (rev 8259)
@@ -1,278 +0,0 @@
-NAME
- Catalyst::Plugin::PageCache - Cache the output of entire pages
-
-SYNOPSIS
- use Catalyst;
- MyApp->setup( qw/Cache::FileCache PageCache/ );
-
- MyApp->config->{page_cache} = {
- expires => 300,
- set_http_headers => 1,
- auto_cache => [
- '/view/.*',
- '/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,
- cache_seconds => 24 * 60 * 60, # once a day
- expires => 300, # allow client caching
- );
-
-DESCRIPTION
- Many dynamic websites perform heavy processing on most pages, yet this
- information may rarely change from request to request. Using the
- PageCache plugin, you can cache the full output of different pages so
- they are served to your visitors as fast as possible. This method of
- caching is very useful for withstanding a Slashdotting, for example.
-
- This plugin requires that you also load a Cache plugin. Please see the
- Known Issues when choosing a cache backend.
-
-WARNINGS
- PageCache should be placed at the end of your plugin list.
-
- You should only use the page cache on pages which have NO user-specific
- or customized content. Also, be careful if caching a page which may
- forward to another controller. For example, if you cache a page behind a
- login screen, the logged-in version may be cached and served to
- unauthenticated users.
-
- Note that pages that result from POST requests will never be cached.
-
-PERFORMANCE
- On my Athlon XP 1800+ Linux server, a cached page is served in 0.008
- seconds when using the HTTP::Daemon server and any of the Cache plugins.
-
-CONFIGURATION
- Configuration is optional. You may define the following configuration
- values:
-
- expires => $seconds
-
- This will set the default expiration time for all page caches. If you do
- not specify this, expiration defaults to 300 seconds (5 minutes).
-
- set_http_headers => 1
-
- Enabling this value will cause Catalyst to set the correct HTTP headers
- to allow browsers and proxy servers to cache your page. This will
- further reduce the load on your server. The headers are set in such a
- way that the browser/proxy cache will expire at the same time as your
- cache. The Last-Modified header will be preserved if you have already
- specified it.
-
- auto_cache => [
- $uri,
- ]
-
- To automatically cache certain pages, or all pages, you can specify
- auto-cache URIs as an array reference. Any controller within your
- application that 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/.*'
-
- debug => 1
-
- This will print additional debugging information to the Catalyst log.
- You will need to have -Debug enabled to see these messages. You can also
- 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.
-
- $c->cache_page( $expire );
-
- The page will be cached for $expire seconds. Every user who visits the
- URI(s) referenced by that controller will receive the page directly from
- cache. Your controller will not be processed again until the cache
- expires. You can set this value to as low as 60 seconds if you have
- heavy traffic to greatly improve site performance.
-
- Pass in a DateTime object to make the cache expire at a given point in
- time.
-
- $two_hours = DateTime->now->add( hours => 2 );
- $c->cache_page( $two_hours );
-
- 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
-
- Pass in a list or hash reference for finer control.
-
- $c->cache_page(
- last_modified => $last_modified,
- cache_seconds => 24 * 60 * 60,
- expires => 30,
- );
-
- This allows separate control of the page cache and the header cache
- values sent to the client.
-
- Possible options are:
-
- last_modified
- Last modified time in epoch seconds. If not set will use either the
- current Last-Modified header, or if not set, 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) than the time that client
- caches may store 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 above, this is a fixed setting that each client will see.
- Regardless of how much longer the page will be cached in the page
- cache the client still sees the same expires time.
-
- Setting zero (0) for expires will result in the page being cached,
- but headers 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.
-
- 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.
-
- $c->clear_cached_page( '/view/userlist' );
- $c->clear_cached_page( '/view/.*' );
-
- This method takes an absolute path or regular expression. For obvious
- reasons, 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.
-
-INTERNAL EXTENDED METHODS
- dispatch
- "dispatch" decides whether or not to serve a particular request from the
- cache.
-
- finalize
- "finalize" caches the result of the current request if needed.
-
- 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,
- you should be serving static files directly from your web server anyway.
-
- Cache::FastMmap does not have the ability to specify different
- expiration times for cached data. Therefore, if your
- MyApp->config->{cache}->{expires} value is set to anything other than 0,
- you may experience problems with the clear_cached_page method, because
- the cache index may be removed. For best results, you may wish to use
- Cache::FileCache or Cache::Memcached as your cache backend.
-
-SEE ALSO
- Catalyst, Catalyst::Plugin::Cache::FastMmap,
- Catalyst::Plugin::Cache::FileCache, Catalyst::Plugin::Cache::Memcached
-
-AUTHOR
- Andy Grundman, <andy at hybridized.org>
-
-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.
-
Copied: tags/Catalyst-Plugin-PageCache/0.19/README (from rev 8258, trunk/Catalyst-Plugin-PageCache/README)
===================================================================
--- tags/Catalyst-Plugin-PageCache/0.19/README (rev 0)
+++ tags/Catalyst-Plugin-PageCache/0.19/README 2008-08-22 17:00:39 UTC (rev 8259)
@@ -0,0 +1,291 @@
+NAME
+ Catalyst::Plugin::PageCache - Cache the output of entire pages
+
+SYNOPSIS
+ use Catalyst;
+ MyApp->setup( qw/Cache::FileCache PageCache/ );
+
+ __PACKAGE__->config(
+ 'Plugin::PageCache' => {
+ expires => 300,
+ set_http_headers => 1,
+ auto_cache => [
+ '/view/.*',
+ '/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 = shift;
+ 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,
+ cache_seconds => 24 * 60 * 60, # once a day
+ expires => 300, # allow client caching
+ );
+
+DESCRIPTION
+ Many dynamic websites perform heavy processing on most pages, yet this
+ information may rarely change from request to request. Using the
+ PageCache plugin, you can cache the full output of different pages so
+ they are served to your visitors as fast as possible. This method of
+ caching is very useful for withstanding a Slashdotting, for example.
+
+ This plugin requires that you also load a Cache plugin. Please see the
+ Known Issues when choosing a cache backend.
+
+WARNINGS
+ PageCache should be placed at the end of your plugin list.
+
+ You should only use the page cache on pages which have NO user-specific
+ or customized content. Also, be careful if caching a page which may
+ forward to another controller. For example, if you cache a page behind a
+ login screen, the logged-in version may be cached and served to
+ unauthenticated users.
+
+ Note that pages that result from POST requests will never be cached.
+
+PERFORMANCE
+ On my Athlon XP 1800+ Linux server, a cached page is served in 0.008
+ seconds when using the HTTP::Daemon server and any of the Cache plugins.
+
+CONFIGURATION
+ Configuration is optional. You may define the following configuration
+ values:
+
+ expires => $seconds
+
+ This will set the default expiration time for all page caches. If you do
+ not specify this, expiration defaults to 300 seconds (5 minutes).
+
+ set_http_headers => 1
+
+ Enabling this value will cause Catalyst to set the correct HTTP headers
+ to allow browsers and proxy servers to cache your page. This will
+ further reduce the load on your server. The headers are set in such a
+ way that the browser/proxy cache will expire at the same time as your
+ cache. The Last-Modified header will be preserved if you have already
+ specified it.
+
+ auto_cache => [
+ $uri,
+ ]
+
+ To automatically cache certain pages, or all pages, you can specify
+ auto-cache URIs as an array reference. Any controller within your
+ application that 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/.*'
+
+ debug => 1
+
+ This will print additional debugging information to the Catalyst log.
+ You will need to have -Debug enabled to see these messages. You can also
+ 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.
+
+ To override the generation of page keys:
+
+ __PACKAGE__->config(
+ 'Plugin::PageCache' => {
+ key_maker => sub {
+ my $c = shift;
+ return $c->req->base . '/' . $c->req->path;
+ }
+ }
+ );
+
+METHODS
+ cache_page
+ Call cache_page in any controller method you wish to be cached.
+
+ $c->cache_page( $expire );
+
+ The page will be cached for $expire seconds. Every user who visits the
+ URI(s) referenced by that controller will receive the page directly from
+ cache. Your controller will not be processed again until the cache
+ expires. You can set this value to as low as 60 seconds if you have
+ heavy traffic to greatly improve site performance.
+
+ Pass in a DateTime object to make the cache expire at a given point in
+ time.
+
+ $two_hours = DateTime->now->add( hours => 2 );
+ $c->cache_page( $two_hours );
+
+ 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
+
+ Pass in a list or hash reference for finer control.
+
+ $c->cache_page(
+ last_modified => $last_modified,
+ cache_seconds => 24 * 60 * 60,
+ expires => 30,
+ );
+
+ This allows separate control of the page cache and the header cache
+ values sent to the client.
+
+ Possible options are:
+
+ last_modified
+ Last modified time in epoch seconds. If not set will use either the
+ current Last-Modified header, or if not set, 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) than the time that client
+ caches may store 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 above, this is a fixed setting that each client will see.
+ Regardless of how much longer the page will be cached in the page
+ cache the client still sees the same expires time.
+
+ Setting zero (0) for expires will result in the page being cached,
+ but headers 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.
+
+ 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.
+
+ $c->clear_cached_page( '/view/userlist' );
+ $c->clear_cached_page( '/view/.*' );
+
+ This method takes an absolute path or regular expression. For obvious
+ reasons, 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.
+
+INTERNAL EXTENDED METHODS
+ dispatch
+ "dispatch" decides whether or not to serve a particular request from the
+ cache.
+
+ finalize
+ "finalize" caches the result of the current request if needed.
+
+ 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,
+ you should be serving static files directly from your web server anyway.
+
+ Cache::FastMmap does not have the ability to specify different
+ expiration times for cached data. Therefore, if your
+ MyApp->config->{cache}->{expires} value is set to anything other than 0,
+ you may experience problems with the clear_cached_page method, because
+ the cache index may be removed. For best results, you may wish to use
+ Cache::FileCache or Cache::Memcached as your cache backend.
+
+SEE ALSO
+ Catalyst, Catalyst::Plugin::Cache::FastMmap,
+ Catalyst::Plugin::Cache::FileCache, Catalyst::Plugin::Cache::Memcached
+
+AUTHOR
+ Andy Grundman, <andy at hybridized.org>
+
+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.
+
Copied: tags/Catalyst-Plugin-PageCache/0.19/TODO (from rev 8258, trunk/Catalyst-Plugin-PageCache/TODO)
===================================================================
--- tags/Catalyst-Plugin-PageCache/0.19/TODO (rev 0)
+++ tags/Catalyst-Plugin-PageCache/0.19/TODO 2008-08-22 17:00:39 UTC (rev 8259)
@@ -0,0 +1 @@
+- disable index stuff by default, make regex clear_cached_page an option
Deleted: tags/Catalyst-Plugin-PageCache/0.19/lib/Catalyst/Plugin/PageCache.pm
===================================================================
--- trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm 2008-08-21 19:46:02 UTC (rev 8250)
+++ tags/Catalyst-Plugin-PageCache/0.19/lib/Catalyst/Plugin/PageCache.pm 2008-08-22 17:00:39 UTC (rev 8259)
@@ -1,655 +0,0 @@
-package Catalyst::Plugin::PageCache;
-
-use strict;
-use base qw/Class::Accessor::Fast/;
-use NEXT;
-
-our $VERSION = '0.18';
-
-# Do we need to cache the current page?
-__PACKAGE__->mk_accessors('_cache_page');
-
-# Keeps track of whether the current request was served from cache
-__PACKAGE__->mk_accessors('_page_cache_used');
-
-# Keeps a safe copy of the initial request parameters, in case the
-# user changes them during processing
-__PACKAGE__->mk_accessors('_page_cache_key');
-
-sub cache_page {
- my ( $c, @args ) = @_;
-
- # Parameters passed in?
-
- if ( ref($args[0]) eq 'HASH' || @args > 1 ) {
- my $options = ref( $args[0] ) ? shift : { @args };
-
- $options->{cache_seconds} = $c->config->{page_cache}->{expires}
- unless exists $options->{cache_seconds};
-
- $c->_cache_page( $options );
- return;
- }
-
- my $expires = shift @args;
-
- # Allow specific end time
- $expires = $expires->epoch - time
- if ref($expires) && $expires->isa('DateTime');
-
-
- $expires ||= $c->config->{page_cache}->{expires};
-
- # mark the page for caching during finalize
- if ( $expires > 0 ) {
- $c->_cache_page( { cache_seconds => $expires } );
- }
-}
-
-sub clear_cached_page {
- my ( $c, $uri ) = @_;
-
- return unless ( $c->can( 'cache' ) );
-
- my $removed = 0;
-
- my $index = $c->cache->get( "_page_cache_index" ) || {};
-
- foreach my $key ( keys %{$index} ) {
- if ( $key =~ /^(?::[^:]+:)?$uri$/xms ) {
- $c->cache->remove( $key );
- delete $index->{$key};
- $removed++;
- $c->log->debug( "Removed $key from page cache" )
- if ( $c->config->{page_cache}->{debug} );
- }
- }
- $c->cache->set( "_page_cache_index", $index,
- $c->config->{page_cache}->{no_expire} ) if ( $removed );
-}
-
-sub dispatch {
- my $c = shift;
-
- # never serve POST request pages from cache
- return $c->NEXT::dispatch(@_) if ( $c->req->method eq "POST" );
-
- my $hook = $c->config->{page_cache}->{cache_hook} ?
- $c->can($c->config->{page_cache}->{cache_hook}) : undef;
- return $c->NEXT::dispatch(@_) if ( $hook && !$c->$hook() );
-
- return $c->NEXT::dispatch(@_) if (
- $c->config->{page_cache}->{auto_check_user} &&
- $c->can('user_exists') &&
- $c->user_exists
- );
-
- # check the page cache for a cached copy of this page
- return $c->NEXT::dispatch(@_)
- unless my $key = $c->_get_page_cache_key;
-
- return $c->NEXT::dispatch(@_)
- unless my $data = $c->cache->get( $key );
-
- # Time to remove page from cache?
-
- if ( $data->{expire_time} and $data->{expire_time} <= time ) {
- $c->log->debug( "Expiring $key from page cache" )
- if ( $c->config->{page_cache}->{debug} );
-
- $c->cache->remove( $key );
-
- my $index = $c->cache->get( "_page_cache_index" ) || {};
- delete $index->{$key};
- $c->cache->set( "_page_cache_index", $index,
- $c->config->{page_cache}->{no_expire} );
-
- return $c->NEXT::dispatch(@_);
- }
-
- $c->log->debug( "Serving $key from page cache, expires in " .
- ( $data->{expire_time} - time ) . " seconds" )
- if ( $c->config->{page_cache}->{debug} );
-
- $c->_page_cache_used( 1 );
-
-
- # Check If-Modified-Since headers
- return 1 if $c->_page_cache_not_modified( $data );
-
-
-
- # Serve cached page
-
- $c->res->body( $data->{body} );
-
- $c->res->content_type( join '; ', @{$data->{content_type}} )
- if $data->{content_type};
-
-
- $c->res->content_encoding( $data->{content_encoding} )
- if $data->{content_encoding};
-
-
- $c->_set_page_cache_headers( $data );
-
- $c->res->header('X-PageCache', 'Catalyst');
-
-}
-
-# See if request matches last_modified date in cache
-# and return true if so.
-
-sub _page_cache_not_modified {
- my ( $c, $data ) = @_;
-
- if ( $c->req->headers->if_modified_since ) {
-
- if ( $c->req->headers->if_modified_since == $data->{create_time} ) {
- $c->res->status(304); # Not Modified
- $c->res->headers->remove_content_headers;
- $c->_set_page_cache_headers( $data );
- $c->res->body( '' );
- return 1;
- }
- }
-
- return;
-}
-
-
-# Sets cache headers for the page if set_http_headers is true.
-
-sub _set_page_cache_headers {
- my ( $c, $data ) = @_;
-
- return unless $c->config->{page_cache}->{set_http_headers};
-
-
- if ( exists $data->{expires} ) {
-
- # page cache but not client cache
- if ( !$data->{expires} ) {
- $c->res->headers->header( 'Cache-Control' => 'no-cache' );
- $c->res->headers->header( 'Pragma' => 'no-cache' );
- return;
- }
-
- $c->res->headers->header( 'Cache-Control' =>
- "max-age=" . $data->{expires} );
-
- $c->res->headers->expires( time + $data->{expires} );
-
- } else {
-
- $c->res->headers->header( 'Cache-Control' =>
- "max-age=" . ( $data->{expire_time} - time ) );
-
- $c->res->headers->expires( $data->{expire_time} );
- }
-
- $c->res->headers->last_modified( $data->{create_time} )
- unless $c->res->status && $c->res->status == 304;
-}
-
-sub finalize {
- my $c = shift;
-
- # never cache POST requests
- return $c->NEXT::finalize(@_) if ( $c->req->method eq "POST" );
-
- my $hook = $c->config->{page_cache}->{cache_hook} ?
- $c->can($c->config->{page_cache}->{cache_hook}) : undef;
- return $c->NEXT::finalize(@_) if ( $hook && !$c->$hook() );
-
-
- return $c->NEXT::finalize(@_) if (
- $c->config->{page_cache}->{auto_check_user} &&
- $c->can('user_exists') &&
- $c->user_exists
- );
- return $c->NEXT::finalize(@_) if ( scalar @{ $c->error } );
-
- # if we already served the current request from cache, we can skip the
- # rest of this method
- return $c->NEXT::finalize(@_) if ( $c->_page_cache_used );
-
- if ( !$c->_cache_page && scalar @{ $c->config->{page_cache}->{auto_cache} } ) {
- # is this page part of the auto_cache list?
- my $path = "/" . $c->req->path;
-
- # For performance, this should be moved to setup, and generate a hash.
- AUTO_CACHE:
- foreach my $auto ( @{ $c->config->{page_cache}->{auto_cache} } ) {
- next if $auto =~ m/^\d$/;
- if ( $path =~ /^$auto$/ ) {
- $c->log->debug( "Auto-caching page $path" )
- if ( $c->config->{page_cache}->{debug} );
- $c->cache_page;
- last AUTO_CACHE;
- }
- }
- }
-
- if ( my $options = $c->_cache_page ) {
- my $key = $c->_get_page_cache_key;
-
- my $now = time;
-
-
- $c->log->debug( "Caching page $key for $options->{cache_seconds} seconds" )
- if ( $c->config->{page_cache}->{debug} );
-
- # Cache some additional metadata along with the content
- # Some caches don't support expirations, so we do it manually
- my $data = {
- body => $c->res->body || undef,
- content_type => [ $c->res->content_type ] || undef,
- content_encoding => $c->res->content_encoding || undef,
- create_time => $options->{last_modified} || $c->res->headers->last_modified || $now,
- expire_time => $now + $options->{cache_seconds},
- };
-
- $data->{expires} = $options->{expires} if exists $options->{expires};
-
- $c->cache->set( $key, $data );
-
- $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
-
- my $index = $c->cache->get( "_page_cache_index" ) || {};
- $index->{$key} = 1;
-
- # Save date in cache
- $c->cache->set( "_page_cache_index", $index,
- $c->config->{page_cache}->{no_expire} );
-
- # Check for If-Modified-Since
- $c->_page_cache_not_modified( $data );
- }
-
- return $c->NEXT::finalize(@_);
-}
-
-sub setup {
- my $c = shift;
-
- $c->NEXT::setup(@_);
-
- $c->config->{page_cache}->{auto_cache} ||= [];
- $c->config->{page_cache}->{expires} ||= 60 * 5;
- $c->config->{page_cache}->{set_http_headers} ||= 0;
- $c->config->{page_cache}->{debug} ||= $c->debug;
-
- # detect the cache plugin being used and set appropriate
- # never-expires syntax
- if ( $c->can('cache') ) {
-
- # Newer C::P::Cache, cannot call $c->cache as a package method
- if ( $c->isa('Catalyst::Plugin::Cache') ) {
- return;
- }
-
- # Older Cache plugins
- if ( $c->cache->isa('Cache::FileCache') ) {
- $c->config->{page_cache}->{no_expire} = "never";
- }
- elsif ( $c->cache->isa('Cache::Memcached') ||
- $c->cache->isa('Cache::FastMmap') ) {
- # Memcached defaults to 'never' when not given an expiration
- # In FastMmap, it's not possible to set an expiration
- $c->config->{page_cache}->{no_expire} = undef;
- }
- }
- else {
- die __PACKAGE__ . " requires a Catalyst::Plugin::Cache plugin.";
- }
-}
-
-sub _get_page_cache_key {
- my $c = shift;
-
- # We can't rely on the params after the user's code has run, so
- # use the key created during the initial dispatch phase
- return $c->_page_cache_key if ( $c->_page_cache_key );
-
- my $key = "/" . $c->req->path;
-
- # prepend language if I18N present.
- if ( $c->can('language') ) {
- $key = ':' . $c->language . ':' . $key;
- }
-
- if ( scalar $c->req->param ) {
- my @params;
- foreach my $arg ( sort keys %{ $c->req->params } ) {
- if ( ref $c->req->params->{$arg} ) {
- my $list = $c->req->params->{$arg};
- push @params, map { "$arg=" . $_ } sort @{$list};
- }
- else {
- push @params, "$arg=" . $c->req->params->{$arg};
- }
- }
- $key .= '?' . join( '&', @params );
- }
- elsif ( my $query = $c->req->uri->query ) {
- $key .= '?' . $query;
- }
-
- $c->_page_cache_key( $key );
-
- return $key;
-}
-
-1;
-__END__
-
-=head1 NAME
-
-Catalyst::Plugin::PageCache - Cache the output of entire pages
-
-=head1 SYNOPSIS
-
- use Catalyst;
- MyApp->setup( qw/Cache::FileCache PageCache/ );
-
- MyApp->config->{page_cache} = {
- expires => 300,
- set_http_headers => 1,
- auto_cache => [
- '/view/.*',
- '/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,
- cache_seconds => 24 * 60 * 60, # once a day
- expires => 300, # allow client caching
- );
-
-=head1 DESCRIPTION
-
-Many dynamic websites perform heavy processing on most pages, yet this
-information may rarely change from request to request. Using the PageCache
-plugin, you can cache the full output of different pages so they are served to
-your visitors as fast as possible. This method of caching is very useful for
-withstanding a Slashdotting, for example.
-
-This plugin requires that you also load a Cache plugin. Please see the Known
-Issues when choosing a cache backend.
-
-=head1 WARNINGS
-
-PageCache should be placed at the end of your plugin list.
-
-You should only use the page cache on pages which have NO user-specific or
-customized content. Also, be careful if caching a page which may forward to
-another controller. For example, if you cache a page behind a login screen,
-the logged-in version may be cached and served to unauthenticated users.
-
-Note that pages that result from POST requests will never be cached.
-
-=head1 PERFORMANCE
-
-On my Athlon XP 1800+ Linux server, a cached page is served in 0.008 seconds
-when using the HTTP::Daemon server and any of the Cache plugins.
-
-=head1 CONFIGURATION
-
-Configuration is optional. You may define the following configuration values:
-
- expires => $seconds
-
-This will set the default expiration time for all page caches. If you do not
-specify this, expiration defaults to 300 seconds (5 minutes).
-
- set_http_headers => 1
-
-Enabling this value will cause Catalyst to set the correct HTTP headers to
-allow browsers and proxy servers to cache your page. This will further reduce
-the load on your server. The headers are set in such a way that the
-browser/proxy cache will expire at the same time as your cache. The
-Last-Modified header will be preserved if you have already specified it.
-
- auto_cache => [
- $uri,
- ]
-
-To automatically cache certain pages, or all pages, you can specify auto-cache
-URIs as an array reference. Any controller within your application that
-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/.*'
-
- debug => 1
-
-This will print additional debugging information to the Catalyst log. You will
-need to have -Debug enabled to see these messages. You can also 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.
-
-=head1 METHODS
-
-=head2 cache_page
-
-Call cache_page in any controller method you wish to be cached.
-
- $c->cache_page( $expire );
-
-The page will be cached for $expire seconds. Every user who visits the URI(s)
-referenced by that controller will receive the page directly from cache. Your
-controller will not be processed again until the cache expires. You can set
-this value to as low as 60 seconds if you have heavy traffic to greatly
-improve site performance.
-
-Pass in a DateTime object to make the cache expire at a given point in time.
-
- $two_hours = DateTime->now->add( hours => 2 );
- $c->cache_page( $two_hours );
-
-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
-
-Pass in a list or hash reference for finer control.
-
- $c->cache_page(
- last_modified => $last_modified,
- cache_seconds => 24 * 60 * 60,
- expires => 30,
- );
-
-This allows separate control of the page cache and the header cache
-values sent to the client.
-
-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 if not set, 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) than the time that client caches may store 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 above, this is a fixed setting that each client will see. Regardless of
-how much longer the page will be cached in the page cache the client still sees
-the same expires time.
-
-Setting zero (0) for expires will result in the page being cached, but headers
-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.
-
- $c->clear_cached_page( '/view/userlist' );
- $c->clear_cached_page( '/view/.*' );
-
-This method takes an absolute path or regular expression. For obvious reasons,
-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.
-
-=head1 INTERNAL EXTENDED METHODS
-
-=head2 dispatch
-
-C<dispatch> decides whether or not to serve a particular request from the cache.
-
-=head2 finalize
-
-C<finalize> caches the result of the current request if needed.
-
-=head2 setup
-
-C<setup> initializes all default values.
-
-=head1 I18N SUPPORT
-
-If your application uses L<Catalyst::Plugin::I18N> for localization, a
-separate cache key will be used for each language a page is displayed in.
-
-=head1 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, you should be
-serving static files directly from your web server anyway.
-
-Cache::FastMmap does not have the ability to specify different expiration times
-for cached data. Therefore, if your MyApp->config->{cache}->{expires} value is
-set to anything other than 0, you may experience problems with the
-clear_cached_page method, because the cache index may be removed. For best
-results, you may wish to use Cache::FileCache or Cache::Memcached as your cache
-backend.
-
-=head1 SEE ALSO
-
-L<Catalyst>, L<Catalyst::Plugin::Cache::FastMmap>,
-L<Catalyst::Plugin::Cache::FileCache>,
-L<Catalyst::Plugin::Cache::Memcached>
-
-=head1 AUTHOR
-
-Andy Grundman, <andy at hybridized.org>
-
-=head1 THANKS
-
-Bill Moseley, <mods at hank.org>, for many patches and tests.
-
-Roberto HenrÃquez, <roberto at freekeylabs.com>, for i18n support.
-
-=head1 COPYRIGHT
-
-This program is free software, you can redistribute it and/or modify it under
-the same terms as Perl itself.
-
-=cut
Copied: tags/Catalyst-Plugin-PageCache/0.19/lib/Catalyst/Plugin/PageCache.pm (from rev 8258, trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm)
===================================================================
--- tags/Catalyst-Plugin-PageCache/0.19/lib/Catalyst/Plugin/PageCache.pm (rev 0)
+++ tags/Catalyst-Plugin-PageCache/0.19/lib/Catalyst/Plugin/PageCache.pm 2008-08-22 17:00:39 UTC (rev 8259)
@@ -0,0 +1,686 @@
+package Catalyst::Plugin::PageCache;
+
+use strict;
+use base qw/Class::Accessor::Fast/;
+use NEXT;
+
+our $VERSION = '0.19';
+
+# Do we need to cache the current page?
+__PACKAGE__->mk_accessors('_cache_page');
+
+# Keeps track of whether the current request was served from cache
+__PACKAGE__->mk_accessors('_page_cache_used');
+
+# Keeps a safe copy of the initial request parameters, in case the
+# user changes them during processing
+__PACKAGE__->mk_accessors('_page_cache_key');
+
+sub cache_page {
+ my ( $c, @args ) = @_;
+
+ # Parameters passed in?
+
+ if ( ref($args[0]) eq 'HASH' || @args > 1 ) {
+ my $options = ref( $args[0] ) ? shift : { @args };
+
+ $options->{cache_seconds} = $c->config->{'Plugin::PageCache'}->{expires}
+ unless exists $options->{cache_seconds};
+
+ $c->_cache_page( $options );
+ return;
+ }
+
+ my $expires = shift @args;
+
+ # Allow specific end time
+ $expires = $expires->epoch - time
+ if ref($expires) && $expires->isa('DateTime');
+
+ $expires ||= $c->config->{'Plugin::PageCache'}->{expires};
+
+ # mark the page for caching during finalize
+ if ( $expires > 0 ) {
+ $c->_cache_page( { cache_seconds => $expires } );
+ }
+}
+
+sub clear_cached_page {
+ my ( $c, $uri ) = @_;
+
+ return unless ( $c->can( 'cache' ) );
+
+ my $is_debug = $c->config->{'Plugin::PageCache'}->{debug};
+
+ my $removed = 0;
+
+ my $index = $c->cache->get( "_page_cache_index" ) || {};
+
+ foreach my $key ( keys %{$index} ) {
+ if ( $key =~ /^(?::[^:]+:)?$uri$/xms ) {
+ $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",
+ $index,
+ $c->config->{'Plugin::PageCache'}->{no_expire}
+ );
+ }
+}
+
+sub dispatch {
+ my $c = shift;
+
+ # never serve POST request pages from cache
+ return $c->NEXT::dispatch(@_) 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::dispatch(@_) if ( $hook && !$c->$hook() );
+
+ return $c->NEXT::dispatch(@_)
+ if ( $c->config->{'Plugin::PageCache'}->{auto_check_user}
+ && $c->can('user_exists')
+ && $c->user_exists);
+
+ # check the page cache for a cached copy of this page
+ return $c->NEXT::dispatch(@_)
+ unless my $key = $c->_get_page_cache_key;
+
+ return $c->NEXT::dispatch(@_)
+ unless my $data = $c->cache->get( $key );
+
+ # Time to remove page from cache?
+
+ if ( $data->{expire_time} and $data->{expire_time} <= time ) {
+ $c->log->debug( "Expiring $key from page cache" )
+ if ($c->config->{'Plugin::PageCache'}->{debug});
+
+ $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});
+
+ return $c->NEXT::dispatch(@_);
+ }
+
+ $c->log->debug("Serving $key from page cache, expires in "
+ . ($data->{expire_time} - time)
+ . " seconds")
+ if ($c->config->{'Plugin::PageCache'}->{debug});
+
+ $c->_page_cache_used( 1 );
+
+ # Check If-Modified-Since headers
+ return 1 if $c->_page_cache_not_modified( $data );
+
+ # Serve cached page
+
+ $c->res->body( $data->{body} );
+
+ $c->res->content_type( join '; ', @{$data->{content_type}} )
+ if $data->{content_type};
+
+ $c->res->content_encoding( $data->{content_encoding} )
+ if $data->{content_encoding};
+
+ $c->_set_page_cache_headers( $data );
+
+ $c->res->header('X-PageCache', 'Catalyst');
+
+}
+
+# See if request matches last_modified date in cache
+# and return true if so.
+
+sub _page_cache_not_modified {
+ my ( $c, $data ) = @_;
+
+ if ( $c->req->headers->if_modified_since ) {
+
+ if ( $c->req->headers->if_modified_since == $data->{create_time} ) {
+ $c->res->status(304); # Not Modified
+ $c->res->headers->remove_content_headers;
+ $c->_set_page_cache_headers( $data );
+ $c->res->body( '' );
+ return 1;
+ }
+ }
+
+ return;
+}
+
+# Sets cache headers for the page if set_http_headers is true.
+
+sub _set_page_cache_headers {
+ my ( $c, $data ) = @_;
+
+ return unless $c->config->{'Plugin::PageCache'}->{set_http_headers};
+
+ if ( exists $data->{expires} ) {
+
+ # page cache but not client cache
+ if ( !$data->{expires} ) {
+ $c->res->headers->header( 'Cache-Control' => 'no-cache' );
+ $c->res->headers->header( 'Pragma' => 'no-cache' );
+ return;
+ }
+
+ $c->res->headers->header(
+ 'Cache-Control' => "max-age=" . $data->{expires});
+
+ $c->res->headers->expires( time + $data->{expires} );
+
+ }
+ else {
+
+ $c->res->headers->header(
+ 'Cache-Control' => "max-age=" . ($data->{expire_time} - time));
+
+ $c->res->headers->expires( $data->{expire_time} );
+ }
+
+ $c->res->headers->last_modified( $data->{create_time} )
+ unless $c->res->status && $c->res->status == 304;
+}
+
+sub finalize {
+ my $c = shift;
+
+ # never cache POST requests
+ return $c->NEXT::finalize(@_) 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::finalize(@_) if ( $hook && !$c->$hook() );
+
+ return $c->NEXT::finalize(@_)
+ if ( $c->config->{'Plugin::PageCache'}->{auto_check_user}
+ && $c->can('user_exists')
+ && $c->user_exists);
+ return $c->NEXT::finalize(@_) if ( scalar @{ $c->error } );
+
+ # if we already served the current request from cache, we can skip the
+ # rest of this method
+ return $c->NEXT::finalize(@_) if ( $c->_page_cache_used );
+
+ if (!$c->_cache_page
+ && scalar @{ $c->config->{'Plugin::PageCache'}->{auto_cache} })
+ {
+
+ # is this page part of the auto_cache list?
+ my $path = "/" . $c->req->path;
+
+ # For performance, this should be moved to setup, and generate a hash.
+ AUTO_CACHE:
+ foreach my $auto (@{ $c->config->{'Plugin::PageCache'}->{auto_cache} })
+ {
+ next if $auto =~ m/^\d$/;
+ if ( $path =~ /^$auto$/ ) {
+ $c->log->debug( "Auto-caching page $path" )
+ if ($c->config->{'Plugin::PageCache'}->{debug});
+ $c->cache_page;
+ last AUTO_CACHE;
+ }
+ }
+ }
+
+ if ( my $options = $c->_cache_page ) {
+ my $key = $c->_get_page_cache_key;
+
+ my $now = time;
+
+ $c->log->debug(
+ "Caching page $key for $options->{cache_seconds} seconds"
+ ) if ($c->config->{'Plugin::PageCache'}->{debug});
+
+ # Cache some additional metadata along with the content
+ # Some caches don't support expirations, so we do it manually
+ my $data = {
+ body => $c->res->body || undef,
+ content_type => [ $c->res->content_type ] || undef,
+ content_encoding => $c->res->content_encoding || undef,
+ create_time => $options->{last_modified}
+ || $c->res->headers->last_modified
+ || $now,
+ expire_time => $now + $options->{cache_seconds},
+ };
+
+ $data->{expires} = $options->{expires} if exists $options->{expires};
+
+ $c->cache->set( $key, $data );
+
+ $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
+
+ 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});
+
+ # Check for If-Modified-Since
+ $c->_page_cache_not_modified( $data );
+ }
+
+ return $c->NEXT::finalize(@_);
+}
+
+sub setup {
+ my $c = shift;
+
+ $c->NEXT::setup(@_);
+
+ # allow code using old config key to work
+ if ( $c->config->{page_cache} and !$c->config->{'Plugin::PageCache'} ) {
+ $c->config->{'Plugin::PageCache'} = delete $c->config->{page_cache};
+ }
+
+ $c->config->{'Plugin::PageCache'}->{auto_cache} ||= [];
+ $c->config->{'Plugin::PageCache'}->{expires} ||= 60 * 5;
+ $c->config->{'Plugin::PageCache'}->{set_http_headers} ||= 0;
+ $c->config->{'Plugin::PageCache'}->{debug} ||= $c->debug;
+
+ # detect the cache plugin being used and set appropriate
+ # never-expires syntax
+ if ( $c->can('cache') ) {
+
+ # Newer C::P::Cache, cannot call $c->cache as a package method
+ if ( $c->isa('Catalyst::Plugin::Cache') ) {
+ return;
+ }
+
+ # Older Cache plugins
+ if ( $c->cache->isa('Cache::FileCache') ) {
+ $c->config->{'Plugin::PageCache'}->{no_expire} = "never";
+ }
+ elsif ($c->cache->isa('Cache::Memcached')
+ || $c->cache->isa('Cache::FastMmap'))
+ {
+
+ # Memcached defaults to 'never' when not given an expiration
+ # In FastMmap, it's not possible to set an expiration
+ $c->config->{'Plugin::PageCache'}->{no_expire} = undef;
+ }
+ }
+ else {
+ die __PACKAGE__ . " requires a Catalyst::Plugin::Cache plugin.";
+ }
+}
+
+sub _get_page_cache_key {
+ my $c = shift;
+
+ # We can't rely on the params after the user's code has run, so
+ # use the key created during the initial dispatch phase
+ return $c->_page_cache_key if ( $c->_page_cache_key );
+
+ # override key if required
+ my $keymaker = $c->config->{'Plugin::PageCache'}->{key_maker};
+ my $key = $keymaker ? $keymaker->($c) : "/" . $c->req->path;
+
+ # prepend language if I18N present.
+ if ( $c->can('language') ) {
+ $key = ':' . $c->language . ':' . $key;
+ }
+
+ if ( scalar $c->req->param ) {
+ my @params;
+ foreach my $arg ( sort keys %{ $c->req->params } ) {
+ if ( ref $c->req->params->{$arg} ) {
+ my $list = $c->req->params->{$arg};
+ push @params, map { "$arg=" . $_ } sort @{$list};
+ }
+ else {
+ push @params, "$arg=" . $c->req->params->{$arg};
+ }
+ }
+ $key .= '?' . join( '&', @params );
+ }
+ elsif ( my $query = $c->req->uri->query ) {
+ $key .= '?' . $query;
+ }
+
+ $c->_page_cache_key( $key );
+
+ return $key;
+}
+
+1;
+__END__
+
+=head1 NAME
+
+Catalyst::Plugin::PageCache - Cache the output of entire pages
+
+=head1 SYNOPSIS
+
+ use Catalyst;
+ MyApp->setup( qw/Cache::FileCache PageCache/ );
+
+ __PACKAGE__->config(
+ 'Plugin::PageCache' => {
+ expires => 300,
+ set_http_headers => 1,
+ auto_cache => [
+ '/view/.*',
+ '/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 = shift;
+ 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,
+ cache_seconds => 24 * 60 * 60, # once a day
+ expires => 300, # allow client caching
+ );
+
+=head1 DESCRIPTION
+
+Many dynamic websites perform heavy processing on most pages, yet this
+information may rarely change from request to request. Using the PageCache
+plugin, you can cache the full output of different pages so they are served to
+your visitors as fast as possible. This method of caching is very useful for
+withstanding a Slashdotting, for example.
+
+This plugin requires that you also load a Cache plugin. Please see the Known
+Issues when choosing a cache backend.
+
+=head1 WARNINGS
+
+PageCache should be placed at the end of your plugin list.
+
+You should only use the page cache on pages which have NO user-specific or
+customized content. Also, be careful if caching a page which may forward to
+another controller. For example, if you cache a page behind a login screen,
+the logged-in version may be cached and served to unauthenticated users.
+
+Note that pages that result from POST requests will never be cached.
+
+=head1 PERFORMANCE
+
+On my Athlon XP 1800+ Linux server, a cached page is served in 0.008 seconds
+when using the HTTP::Daemon server and any of the Cache plugins.
+
+=head1 CONFIGURATION
+
+Configuration is optional. You may define the following configuration values:
+
+ expires => $seconds
+
+This will set the default expiration time for all page caches. If you do not
+specify this, expiration defaults to 300 seconds (5 minutes).
+
+ set_http_headers => 1
+
+Enabling this value will cause Catalyst to set the correct HTTP headers to
+allow browsers and proxy servers to cache your page. This will further reduce
+the load on your server. The headers are set in such a way that the
+browser/proxy cache will expire at the same time as your cache. The
+Last-Modified header will be preserved if you have already specified it.
+
+ auto_cache => [
+ $uri,
+ ]
+
+To automatically cache certain pages, or all pages, you can specify auto-cache
+URIs as an array reference. Any controller within your application that
+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/.*'
+
+ debug => 1
+
+This will print additional debugging information to the Catalyst log. You will
+need to have -Debug enabled to see these messages. You can also 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.
+
+To override the generation of page keys:
+
+ __PACKAGE__->config(
+ 'Plugin::PageCache' => {
+ key_maker => sub {
+ my $c = shift;
+ return $c->req->base . '/' . $c->req->path;
+ }
+ }
+ );
+
+=head1 METHODS
+
+=head2 cache_page
+
+Call cache_page in any controller method you wish to be cached.
+
+ $c->cache_page( $expire );
+
+The page will be cached for $expire seconds. Every user who visits the URI(s)
+referenced by that controller will receive the page directly from cache. Your
+controller will not be processed again until the cache expires. You can set
+this value to as low as 60 seconds if you have heavy traffic to greatly
+improve site performance.
+
+Pass in a DateTime object to make the cache expire at a given point in time.
+
+ $two_hours = DateTime->now->add( hours => 2 );
+ $c->cache_page( $two_hours );
+
+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
+
+Pass in a list or hash reference for finer control.
+
+ $c->cache_page(
+ last_modified => $last_modified,
+ cache_seconds => 24 * 60 * 60,
+ expires => 30,
+ );
+
+This allows separate control of the page cache and the header cache
+values sent to the client.
+
+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 if not set, 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) than the time that client caches may store 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 above, this is a fixed setting that each client will see. Regardless of
+how much longer the page will be cached in the page cache the client still sees
+the same expires time.
+
+Setting zero (0) for expires will result in the page being cached, but headers
+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.
+
+ $c->clear_cached_page( '/view/userlist' );
+ $c->clear_cached_page( '/view/.*' );
+
+This method takes an absolute path or regular expression. For obvious reasons,
+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.
+
+=head1 INTERNAL EXTENDED METHODS
+
+=head2 dispatch
+
+C<dispatch> decides whether or not to serve a particular request from the cache.
+
+=head2 finalize
+
+C<finalize> caches the result of the current request if needed.
+
+=head2 setup
+
+C<setup> initializes all default values.
+
+=head1 I18N SUPPORT
+
+If your application uses L<Catalyst::Plugin::I18N> for localization, a
+separate cache key will be used for each language a page is displayed in.
+
+=head1 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, you should be
+serving static files directly from your web server anyway.
+
+Cache::FastMmap does not have the ability to specify different expiration times
+for cached data. Therefore, if your MyApp->config->{cache}->{expires} value is
+set to anything other than 0, you may experience problems with the
+clear_cached_page method, because the cache index may be removed. For best
+results, you may wish to use Cache::FileCache or Cache::Memcached as your cache
+backend.
+
+=head1 SEE ALSO
+
+L<Catalyst>, L<Catalyst::Plugin::Cache::FastMmap>,
+L<Catalyst::Plugin::Cache::FileCache>,
+L<Catalyst::Plugin::Cache::Memcached>
+
+=head1 AUTHOR
+
+Andy Grundman, <andy at hybridized.org>
+
+=head1 THANKS
+
+Bill Moseley, <mods at hank.org>, for many patches and tests.
+
+Roberto HenrÃquez, <roberto at freekeylabs.com>, for i18n support.
+
+=head1 COPYRIGHT
+
+This program is free software, you can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut
Deleted: tags/Catalyst-Plugin-PageCache/0.19/t/05expires.t
===================================================================
--- trunk/Catalyst-Plugin-PageCache/t/05expires.t 2008-08-21 19:46:02 UTC (rev 8250)
+++ tags/Catalyst-Plugin-PageCache/0.19/t/05expires.t 2008-08-22 17:00:39 UTC (rev 8259)
@@ -1,39 +0,0 @@
-#!perl
-
-use strict;
-use warnings;
-
-use FindBin;
-use lib "$FindBin::Bin/lib";
-use Test::More;
-use File::Path;
-
-BEGIN {
- eval "use Catalyst::Plugin::Cache::FileCache";
- plan $@
- ? ( skip_all => 'needs Catalyst::Plugin::Cache::FileCache for testing' )
- : ( tests => 6 );
-}
-
-# remove previous cache
-rmtree 't/var' if -d 't/var';
-
-use Catalyst::Test 'TestApp';
-
-# add config option
-TestApp->config->{page_cache}->{expires} = 2;
-
-# cache a page
-ok( my $res = request('http://localhost/cache/count'), 'request ok' );
-is( $res->content, 1, 'count is 1' );
-
-# page will be served from cache
-ok( $res = request('http://localhost/cache/count'), 'request ok' );
-is( $res->content, 1, 'count is still 1 from cache' );
-
-# wait...
-sleep 3;
-
-# cache should have expired
-ok( $res = request('http://localhost/cache/count'), 'request ok' );
-is( $res->content, 2, 'count after cache expired is 2' );
Copied: tags/Catalyst-Plugin-PageCache/0.19/t/05expires.t (from rev 8258, trunk/Catalyst-Plugin-PageCache/t/05expires.t)
===================================================================
--- tags/Catalyst-Plugin-PageCache/0.19/t/05expires.t (rev 0)
+++ tags/Catalyst-Plugin-PageCache/0.19/t/05expires.t 2008-08-22 17:00:39 UTC (rev 8259)
@@ -0,0 +1,39 @@
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+use Test::More;
+use File::Path;
+
+BEGIN {
+ eval "use Catalyst::Plugin::Cache::FileCache";
+ plan $@
+ ? ( skip_all => 'needs Catalyst::Plugin::Cache::FileCache for testing' )
+ : ( tests => 6 );
+}
+
+# remove previous cache
+rmtree 't/var' if -d 't/var';
+
+use Catalyst::Test 'TestApp';
+
+# add config option
+TestApp->config->{'Plugin::PageCache'}->{expires} = 2;
+
+# cache a page
+ok( my $res = request('http://localhost/cache/count'), 'request ok' );
+is( $res->content, 1, 'count is 1' );
+
+# page will be served from cache
+ok( $res = request('http://localhost/cache/count'), 'request ok' );
+is( $res->content, 1, 'count is still 1 from cache' );
+
+# wait...
+sleep 3;
+
+# cache should have expired
+ok( $res = request('http://localhost/cache/count'), 'request ok' );
+is( $res->content, 2, 'count after cache expired is 2' );
Deleted: tags/Catalyst-Plugin-PageCache/0.19/t/06auto_cache.t
===================================================================
--- trunk/Catalyst-Plugin-PageCache/t/06auto_cache.t 2008-08-21 19:46:02 UTC (rev 8250)
+++ tags/Catalyst-Plugin-PageCache/0.19/t/06auto_cache.t 2008-08-22 17:00:39 UTC (rev 8259)
@@ -1,46 +0,0 @@
-#!perl
-
-use strict;
-use warnings;
-
-use FindBin;
-use lib "$FindBin::Bin/lib";
-use Test::More;
-use File::Path;
-
-BEGIN {
- eval "use Catalyst::Plugin::Cache::FileCache";
- plan $@
- ? ( skip_all => 'needs Catalyst::Plugin::Cache::FileCache for testing' )
- : ( tests => 8 );
-}
-
-# remove previous cache
-rmtree 't/var' if -d 't/var';
-
-use Catalyst::Test 'TestApp';
-
-# add config option
-TestApp->config->{page_cache}->{auto_cache} = [
- '/cache/auto_count',
- '/cache/another.+',
-];
-
-# cache a page
-ok( my $res = request('http://localhost/cache/auto_count'), 'request ok' );
-is( $res->content, 1, 'count is 1' );
-
-# page will be served from cache
-ok( $res = request('http://localhost/cache/auto_count'), 'request ok' );
-is( $res->content, 1, 'count is still 1 from cache' );
-
-# test regex auto cache
-ok( $res = request('http://localhost/cache/another_auto_count'), 'request ok' );
-is( $res->content, 2, 'count is 2' );
-
-# page will be served from cache
-ok( $res = request('http://localhost/cache/another_auto_count'), 'request ok' );
-is( $res->content, 2, 'count is still 2 from cache' );
-
-
-
Copied: tags/Catalyst-Plugin-PageCache/0.19/t/06auto_cache.t (from rev 8258, trunk/Catalyst-Plugin-PageCache/t/06auto_cache.t)
===================================================================
--- tags/Catalyst-Plugin-PageCache/0.19/t/06auto_cache.t (rev 0)
+++ tags/Catalyst-Plugin-PageCache/0.19/t/06auto_cache.t 2008-08-22 17:00:39 UTC (rev 8259)
@@ -0,0 +1,46 @@
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+use Test::More;
+use File::Path;
+
+BEGIN {
+ eval "use Catalyst::Plugin::Cache::FileCache";
+ plan $@
+ ? ( skip_all => 'needs Catalyst::Plugin::Cache::FileCache for testing' )
+ : ( tests => 8 );
+}
+
+# remove previous cache
+rmtree 't/var' if -d 't/var';
+
+use Catalyst::Test 'TestApp';
+
+# add config option
+TestApp->config->{'Plugin::PageCache'}->{auto_cache} = [
+ '/cache/auto_count',
+ '/cache/another.+',
+];
+
+# cache a page
+ok( my $res = request('http://localhost/cache/auto_count'), 'request ok' );
+is( $res->content, 1, 'count is 1' );
+
+# page will be served from cache
+ok( $res = request('http://localhost/cache/auto_count'), 'request ok' );
+is( $res->content, 1, 'count is still 1 from cache' );
+
+# test regex auto cache
+ok( $res = request('http://localhost/cache/another_auto_count'), 'request ok' );
+is( $res->content, 2, 'count is 2' );
+
+# page will be served from cache
+ok( $res = request('http://localhost/cache/another_auto_count'), 'request ok' );
+is( $res->content, 2, 'count is still 2 from cache' );
+
+
+
Deleted: tags/Catalyst-Plugin-PageCache/0.19/t/07set_http_headers.t
===================================================================
--- trunk/Catalyst-Plugin-PageCache/t/07set_http_headers.t 2008-08-21 19:46:02 UTC (rev 8250)
+++ tags/Catalyst-Plugin-PageCache/0.19/t/07set_http_headers.t 2008-08-22 17:00:39 UTC (rev 8259)
@@ -1,41 +0,0 @@
-#!perl
-
-use strict;
-use warnings;
-
-use FindBin;
-use lib "$FindBin::Bin/lib";
-use Test::More;
-use File::Path;
-
-BEGIN {
- eval "use Catalyst::Plugin::Cache::FileCache";
- plan $@
- ? ( skip_all => 'needs Catalyst::Plugin::Cache::FileCache for testing' )
- : ( tests => 7 );
-}
-
-# remove previous cache
-rmtree 't/var' if -d 't/var';
-
-use Catalyst::Test 'TestApp';
-
-# add config option
-TestApp->config->{page_cache}->{set_http_headers} = 1;
-
-# cache a page
-my $cache_time = time;
-ok( my $res = request('http://localhost/cache/count'), 'request ok' );
-is( $res->content, 1, 'count is 1' );
-
-# page will be served from cache and have http headers
-ok( $res = request('http://localhost/cache/count'), 'request ok' );
-is( $res->content, 1, 'count is still 1 from cache' );
-
-# avoid race conditions by not testing for exact times
-like( $res->headers->{'cache-control'}, qr/max-age=\d{3}/, 'cache-control header ok' );
-cmp_ok( $res->headers->last_modified, '>=', $cache_time, 'last-modified header matches correct time' );
-cmp_ok( $res->headers->expires, '>=', $cache_time + 300, 'expires header matches correct time' );
-
-
-
Copied: tags/Catalyst-Plugin-PageCache/0.19/t/07set_http_headers.t (from rev 8258, trunk/Catalyst-Plugin-PageCache/t/07set_http_headers.t)
===================================================================
--- tags/Catalyst-Plugin-PageCache/0.19/t/07set_http_headers.t (rev 0)
+++ tags/Catalyst-Plugin-PageCache/0.19/t/07set_http_headers.t 2008-08-22 17:00:39 UTC (rev 8259)
@@ -0,0 +1,41 @@
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+use Test::More;
+use File::Path;
+
+BEGIN {
+ eval "use Catalyst::Plugin::Cache::FileCache";
+ plan $@
+ ? ( skip_all => 'needs Catalyst::Plugin::Cache::FileCache for testing' )
+ : ( tests => 7 );
+}
+
+# remove previous cache
+rmtree 't/var' if -d 't/var';
+
+use Catalyst::Test 'TestApp';
+
+# add config option
+TestApp->config->{'Plugin::PageCache'}->{set_http_headers} = 1;
+
+# cache a page
+my $cache_time = time;
+ok( my $res = request('http://localhost/cache/count'), 'request ok' );
+is( $res->content, 1, 'count is 1' );
+
+# page will be served from cache and have http headers
+ok( $res = request('http://localhost/cache/count'), 'request ok' );
+is( $res->content, 1, 'count is still 1 from cache' );
+
+# avoid race conditions by not testing for exact times
+like( $res->headers->{'cache-control'}, qr/max-age=\d{3}/, 'cache-control header ok' );
+cmp_ok( $res->headers->last_modified, '>=', $cache_time, 'last-modified header matches correct time' );
+cmp_ok( $res->headers->expires, '>=', $cache_time + 300, 'expires header matches correct time' );
+
+
+
Deleted: tags/Catalyst-Plugin-PageCache/0.19/t/09datetime.t
===================================================================
--- trunk/Catalyst-Plugin-PageCache/t/09datetime.t 2008-08-21 19:46:02 UTC (rev 8250)
+++ tags/Catalyst-Plugin-PageCache/0.19/t/09datetime.t 2008-08-22 17:00:39 UTC (rev 8259)
@@ -1,54 +0,0 @@
-#!perl
-
-use strict;
-use warnings;
-
-use FindBin;
-use lib "$FindBin::Bin/lib";
-use Test::More;
-use File::Path;
-
-BEGIN {
- eval "use Catalyst::Plugin::Cache::FileCache";
- if ( $@ ) {
- plan ( skip_all => 'needs Catalyst::Plugin::Cache::FileCache for testing' );
- } else {
- eval "use DateTime";
- if ( $@ ) {
- plan ( skip_all => 'needs DateTime for testing' );
- } else {
- plan ( tests => 7 );
- }
- }
-}
-
-# This tests that a DateTime object can be passed in.
-
-# remove previous cache
-rmtree 't/var' if -d 't/var';
-
-use Catalyst::Test 'TestApp';
-
-# add config option
-TestApp->config->{page_cache}->{set_http_headers} = 1;
-
-# cache a page
-my $cache_time = time;
-ok( my $res = request('http://localhost/cache/test_datetime'), 'request ok' );
-is( $res->content, 1, 'count is 1' );
-
-# page will be served from cache and have http headers
-ok( $res = request('http://localhost/cache/test_datetime'), 'request ok' );
-is( $res->content, 1, 'count is still 1 from cache' );
-
-# avoid race conditions by not testing for exact times
-like( $res->headers->{'cache-control'}, qr/max-age=\d{3}/, 'cache-control header ok' );
-cmp_ok( $res->headers->last_modified, '>=', $cache_time, 'last-modified header matches correct time' );
-
-require DateTime;
-
-my $dt_epoch = DateTime->new( day => 24, month => 1, year => 2026, time_zone => 'UTC' )->epoch;
-is( $res->headers->expires, $dt_epoch, 'expires header matches correct time' );
-
-
-
Copied: tags/Catalyst-Plugin-PageCache/0.19/t/09datetime.t (from rev 8258, trunk/Catalyst-Plugin-PageCache/t/09datetime.t)
===================================================================
--- tags/Catalyst-Plugin-PageCache/0.19/t/09datetime.t (rev 0)
+++ tags/Catalyst-Plugin-PageCache/0.19/t/09datetime.t 2008-08-22 17:00:39 UTC (rev 8259)
@@ -0,0 +1,54 @@
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+use Test::More;
+use File::Path;
+
+BEGIN {
+ eval "use Catalyst::Plugin::Cache::FileCache";
+ if ( $@ ) {
+ plan ( skip_all => 'needs Catalyst::Plugin::Cache::FileCache for testing' );
+ } else {
+ eval "use DateTime";
+ if ( $@ ) {
+ plan ( skip_all => 'needs DateTime for testing' );
+ } else {
+ plan ( tests => 7 );
+ }
+ }
+}
+
+# This tests that a DateTime object can be passed in.
+
+# remove previous cache
+rmtree 't/var' if -d 't/var';
+
+use Catalyst::Test 'TestApp';
+
+# add config option
+TestApp->config->{'Plugin::PageCache'}->{set_http_headers} = 1;
+
+# cache a page
+my $cache_time = time;
+ok( my $res = request('http://localhost/cache/test_datetime'), 'request ok' );
+is( $res->content, 1, 'count is 1' );
+
+# page will be served from cache and have http headers
+ok( $res = request('http://localhost/cache/test_datetime'), 'request ok' );
+is( $res->content, 1, 'count is still 1 from cache' );
+
+# avoid race conditions by not testing for exact times
+like( $res->headers->{'cache-control'}, qr/max-age=\d{3}/, 'cache-control header ok' );
+cmp_ok( $res->headers->last_modified, '>=', $cache_time, 'last-modified header matches correct time' );
+
+require DateTime;
+
+my $dt_epoch = DateTime->new( day => 24, month => 1, year => 2026, time_zone => 'UTC' )->epoch;
+is( $res->headers->expires, $dt_epoch, 'expires header matches correct time' );
+
+
+
Deleted: tags/Catalyst-Plugin-PageCache/0.19/t/10options.t
===================================================================
--- trunk/Catalyst-Plugin-PageCache/t/10options.t 2008-08-21 19:46:02 UTC (rev 8250)
+++ tags/Catalyst-Plugin-PageCache/0.19/t/10options.t 2008-08-22 17:00:39 UTC (rev 8259)
@@ -1,42 +0,0 @@
-#!perl
-
-use strict;
-use warnings;
-
-use FindBin;
-use lib "$FindBin::Bin/lib";
-use Test::More;
-use File::Path;
-
-BEGIN {
- eval "use Catalyst::Plugin::Cache::FileCache";
- plan $@
- ? ( skip_all => 'needs Catalyst::Plugin::Cache::FileCache for testing' )
- : ( tests => 7 );
-}
-
-# This test that options can be passed to cache.
-
-# remove previous cache
-rmtree 't/var' if -d 't/var';
-
-use Catalyst::Test 'TestApp';
-
-# add config option
-TestApp->config->{page_cache}->{set_http_headers} = 1;
-
-# cache a page
-my $cache_time = time;
-ok( my $res = request('http://localhost/cache/extra_options'), 'request ok' );
-is( $res->content, 1, 'count is 1' );
-
-# page will be served from cache and have http headers
-ok( $res = request('http://localhost/cache/extra_options'), 'request ok' );
-is( $res->content, 1, 'count is still 1 from cache' );
-
-like( $res->headers->{'cache-control'}, qr/max-age=60/, 'cache-control header ok' );
-cmp_ok( $res->headers->last_modified, '>=', $cache_time, 'last-modified header matches correct time' );
-cmp_ok( $res->headers->expires, '>=', $cache_time + 60, 'expires header matches correct time' );
-
-
-
Copied: tags/Catalyst-Plugin-PageCache/0.19/t/10options.t (from rev 8258, trunk/Catalyst-Plugin-PageCache/t/10options.t)
===================================================================
--- tags/Catalyst-Plugin-PageCache/0.19/t/10options.t (rev 0)
+++ tags/Catalyst-Plugin-PageCache/0.19/t/10options.t 2008-08-22 17:00:39 UTC (rev 8259)
@@ -0,0 +1,42 @@
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+use Test::More;
+use File::Path;
+
+BEGIN {
+ eval "use Catalyst::Plugin::Cache::FileCache";
+ plan $@
+ ? ( skip_all => 'needs Catalyst::Plugin::Cache::FileCache for testing' )
+ : ( tests => 7 );
+}
+
+# This test that options can be passed to cache.
+
+# remove previous cache
+rmtree 't/var' if -d 't/var';
+
+use Catalyst::Test 'TestApp';
+
+# add config option
+TestApp->config->{'Plugin::PageCache'}->{set_http_headers} = 1;
+
+# cache a page
+my $cache_time = time;
+ok( my $res = request('http://localhost/cache/extra_options'), 'request ok' );
+is( $res->content, 1, 'count is 1' );
+
+# page will be served from cache and have http headers
+ok( $res = request('http://localhost/cache/extra_options'), 'request ok' );
+is( $res->content, 1, 'count is still 1 from cache' );
+
+like( $res->headers->{'cache-control'}, qr/max-age=60/, 'cache-control header ok' );
+cmp_ok( $res->headers->last_modified, '>=', $cache_time, 'last-modified header matches correct time' );
+cmp_ok( $res->headers->expires, '>=', $cache_time + 60, 'expires header matches correct time' );
+
+
+
Deleted: tags/Catalyst-Plugin-PageCache/0.19/t/11nocache.t
===================================================================
--- trunk/Catalyst-Plugin-PageCache/t/11nocache.t 2008-08-21 19:46:02 UTC (rev 8250)
+++ tags/Catalyst-Plugin-PageCache/0.19/t/11nocache.t 2008-08-22 17:00:39 UTC (rev 8259)
@@ -1,42 +0,0 @@
-#!perl
-
-use strict;
-use warnings;
-
-use FindBin;
-use lib "$FindBin::Bin/lib";
-use Test::More;
-use File::Path;
-
-BEGIN {
- eval "use Catalyst::Plugin::Cache::FileCache";
- plan $@
- ? ( skip_all => 'needs Catalyst::Plugin::Cache::FileCache for testing' )
- : ( tests => 7 );
-}
-
-# This test that options can be passed to cache.
-
-# remove previous cache
-rmtree 't/var' if -d 't/var';
-
-use Catalyst::Test 'TestApp';
-
-# add config option
-TestApp->config->{page_cache}->{set_http_headers} = 1;
-
-# cache a page
-my $cache_time = time;
-ok( my $res = request('http://localhost/cache/no_cache'), 'request ok' );
-is( $res->content, 1, 'count is 1' );
-
-# page will be served from cache and have http headers
-ok( $res = request('http://localhost/cache/no_cache'), 'request ok' );
-is( $res->content, 1, 'count is still 1 from cache' );
-
-is( $res->headers->{'cache-control'}, 'no-cache', 'cache-control header ok' );
-is( $res->headers->{'pragma'}, 'no-cache', 'pragma header ok' );
-ok( !$res->headers->last_modified, 'last-modified header not included' );
-
-
-
Copied: tags/Catalyst-Plugin-PageCache/0.19/t/11nocache.t (from rev 8258, trunk/Catalyst-Plugin-PageCache/t/11nocache.t)
===================================================================
--- tags/Catalyst-Plugin-PageCache/0.19/t/11nocache.t (rev 0)
+++ tags/Catalyst-Plugin-PageCache/0.19/t/11nocache.t 2008-08-22 17:00:39 UTC (rev 8259)
@@ -0,0 +1,42 @@
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+use Test::More;
+use File::Path;
+
+BEGIN {
+ eval "use Catalyst::Plugin::Cache::FileCache";
+ plan $@
+ ? ( skip_all => 'needs Catalyst::Plugin::Cache::FileCache for testing' )
+ : ( tests => 7 );
+}
+
+# This test that options can be passed to cache.
+
+# remove previous cache
+rmtree 't/var' if -d 't/var';
+
+use Catalyst::Test 'TestApp';
+
+# add config option
+TestApp->config->{'Plugin::PageCache'}->{set_http_headers} = 1;
+
+# cache a page
+my $cache_time = time;
+ok( my $res = request('http://localhost/cache/no_cache'), 'request ok' );
+is( $res->content, 1, 'count is 1' );
+
+# page will be served from cache and have http headers
+ok( $res = request('http://localhost/cache/no_cache'), 'request ok' );
+is( $res->content, 1, 'count is still 1 from cache' );
+
+is( $res->headers->{'cache-control'}, 'no-cache', 'cache-control header ok' );
+is( $res->headers->{'pragma'}, 'no-cache', 'pragma header ok' );
+ok( !$res->headers->last_modified, 'last-modified header not included' );
+
+
+
Deleted: tags/Catalyst-Plugin-PageCache/0.19/t/13cachehook.t
===================================================================
--- trunk/Catalyst-Plugin-PageCache/t/13cachehook.t 2008-08-21 19:46:02 UTC (rev 8250)
+++ tags/Catalyst-Plugin-PageCache/0.19/t/13cachehook.t 2008-08-22 17:00:39 UTC (rev 8259)
@@ -1,62 +0,0 @@
-#!perl
-
-use strict;
-use warnings;
-no warnings 'redefine';
-
-use FindBin;
-use lib "$FindBin::Bin/lib";
-use Test::More;
-use File::Path;
-
-BEGIN {
- eval "use Catalyst::Plugin::Cache::FileCache";
- plan $@
- ? ( skip_all => 'needs Catalyst::Plugin::Cache::FileCache for testing' )
- : ( tests => 16 );
-}
-
-# This test that options can be passed to cache.
-
-# remove previous cache
-rmtree 't/var' if -d 't/var';
-
-use Catalyst::Test 'TestApp';
-
-# add config option
-TestApp->config->{page_cache}->{set_http_headers} = 1;
-TestApp->config->{page_cache}->{cache_hook} = 'use_pagecache';
-
-local *TestApp::use_pagecache = sub { 0 };
-cmp_ok( TestApp->use_pagecache(), '==', '0' );
-
-# Load the page that can be cached, but we shouldn't cache it because of
-# use_pagecache
-ok( my $res = request('http://localhost/cache/no_cache'), 'request ok' );
-is( $res->content, 1, 'count is 1' );
-
-# Page won't be served from cache, and shouldn't have any headers
-ok( $res = request('http://localhost/cache/no_cache'), 'request ok' );
-is( $res->content, 2, 'count is 2' );
-
-isnt( $res->headers->{'cache-control'}, 'no-cache', 'cache-control header ok' );
-isnt( $res->headers->{'pragma'}, 'no-cache', 'pragma header ok' );
-ok( !$res->headers->last_modified, 'last-modified header not included' );
-
-local *TestApp::use_pagecache = sub { 1 };
-cmp_ok( TestApp->use_pagecache(), '==', '1' );
-
-# page will not be served from cache, but will be next request.
-ok( $res = request('http://localhost/cache/no_cache'), 'request ok' );
-is( $res->content, 3, 'count is 3' );
-
-# page will be served from cache and have http headers
-ok( $res = request('http://localhost/cache/no_cache'), 'request ok' );
-is( $res->content, 3, 'count is still 3' );
-
-is( $res->headers->{'cache-control'}, 'no-cache', 'cache-control header ok' );
-is( $res->headers->{'pragma'}, 'no-cache', 'pragma header ok' );
-ok( !$res->headers->last_modified, 'last-modified header not included' );
-
-
-
Copied: tags/Catalyst-Plugin-PageCache/0.19/t/13cachehook.t (from rev 8258, trunk/Catalyst-Plugin-PageCache/t/13cachehook.t)
===================================================================
--- tags/Catalyst-Plugin-PageCache/0.19/t/13cachehook.t (rev 0)
+++ tags/Catalyst-Plugin-PageCache/0.19/t/13cachehook.t 2008-08-22 17:00:39 UTC (rev 8259)
@@ -0,0 +1,62 @@
+#!perl
+
+use strict;
+use warnings;
+no warnings 'redefine';
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+use Test::More;
+use File::Path;
+
+BEGIN {
+ eval "use Catalyst::Plugin::Cache::FileCache";
+ plan $@
+ ? ( skip_all => 'needs Catalyst::Plugin::Cache::FileCache for testing' )
+ : ( tests => 16 );
+}
+
+# This test that options can be passed to cache.
+
+# remove previous cache
+rmtree 't/var' if -d 't/var';
+
+use Catalyst::Test 'TestApp';
+
+# add config option
+TestApp->config->{'Plugin::PageCache'}->{set_http_headers} = 1;
+TestApp->config->{'Plugin::PageCache'}->{cache_hook} = 'use_pagecache';
+
+local *TestApp::use_pagecache = sub { 0 };
+cmp_ok( TestApp->use_pagecache(), '==', '0' );
+
+# Load the page that can be cached, but we shouldn't cache it because of
+# use_pagecache
+ok( my $res = request('http://localhost/cache/no_cache'), 'request ok' );
+is( $res->content, 1, 'count is 1' );
+
+# Page won't be served from cache, and shouldn't have any headers
+ok( $res = request('http://localhost/cache/no_cache'), 'request ok' );
+is( $res->content, 2, 'count is 2' );
+
+isnt( $res->headers->{'cache-control'}, 'no-cache', 'cache-control header ok' );
+isnt( $res->headers->{'pragma'}, 'no-cache', 'pragma header ok' );
+ok( !$res->headers->last_modified, 'last-modified header not included' );
+
+local *TestApp::use_pagecache = sub { 1 };
+cmp_ok( TestApp->use_pagecache(), '==', '1' );
+
+# page will not be served from cache, but will be next request.
+ok( $res = request('http://localhost/cache/no_cache'), 'request ok' );
+is( $res->content, 3, 'count is 3' );
+
+# page will be served from cache and have http headers
+ok( $res = request('http://localhost/cache/no_cache'), 'request ok' );
+is( $res->content, 3, 'count is still 3' );
+
+is( $res->headers->{'cache-control'}, 'no-cache', 'cache-control header ok' );
+is( $res->headers->{'pragma'}, 'no-cache', 'pragma header ok' );
+ok( !$res->headers->last_modified, 'last-modified header not included' );
+
+
+
Copied: tags/Catalyst-Plugin-PageCache/0.19/t/14keymaker.t (from rev 8258, trunk/Catalyst-Plugin-PageCache/t/14keymaker.t)
===================================================================
--- tags/Catalyst-Plugin-PageCache/0.19/t/14keymaker.t (rev 0)
+++ tags/Catalyst-Plugin-PageCache/0.19/t/14keymaker.t 2008-08-22 17:00:39 UTC (rev 8259)
@@ -0,0 +1,47 @@
+#!perl
+
+use strict;
+use warnings;
+no warnings 'redefine';
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+use Test::More;
+use File::Path;
+
+BEGIN {
+ eval "use Catalyst::Plugin::Cache::FileCache";
+ plan $@
+ ? ( skip_all => 'needs Catalyst::Plugin::Cache::FileCache for testing' )
+ : ( tests => 8 );
+}
+
+# This test that options can be passed to cache.
+
+# remove previous cache
+rmtree 't/var' if -d 't/var';
+
+use Catalyst::Test 'TestApp';
+
+# add config option
+# cannot call TestApp->config() because TestApp has already called setup
+TestApp->config->{'Plugin::PageCache'}->{key_maker} = sub {
+ my ($c) = @_;
+ return $c->req->base . q{/} . $c->req->path;
+};
+
+# cache a page
+ok( my $res = request('http://host1/cache/count'), 'request ok' );
+is( $res->content, 1, 'count is 1' );
+
+# page will be served from cache
+ok( $res = request('http://host1/cache/count'), 'request ok' );
+is( $res->content, 1, 'count is still 1 from cache' );
+
+# page will not be served from cache
+ok( $res = request('http://host2/cache/count'), 'request ok' );
+is( $res->content, 2, 'count is 2 from cache' );
+
+# page will be served from cache
+ok( $res = request('http://host2/cache/count'), 'request ok' );
+is( $res->content, 2, 'count is still 2 from cache' );
More information about the Catalyst-commits
mailing list