[Catalyst-commits] r6592 - in trunk/Catalyst-Plugin-PageCache: .
lib/Catalyst/Plugin t
andyg at dev.catalyst.perl.org
andyg at dev.catalyst.perl.org
Tue Jul 24 16:06:02 GMT 2007
Author: andyg
Date: 2007-07-24 16:06:02 +0100 (Tue, 24 Jul 2007)
New Revision: 6592
Removed:
trunk/Catalyst-Plugin-PageCache/Build.PL
trunk/Catalyst-Plugin-PageCache/MANIFEST
Modified:
trunk/Catalyst-Plugin-PageCache/Changes
trunk/Catalyst-Plugin-PageCache/Makefile.PL
trunk/Catalyst-Plugin-PageCache/README
trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm
trunk/Catalyst-Plugin-PageCache/t/04cache.t
Log:
PageCache 0.16, fixed cache key when there is a query string without params, switched to M::I
Deleted: trunk/Catalyst-Plugin-PageCache/Build.PL
===================================================================
--- trunk/Catalyst-Plugin-PageCache/Build.PL 2007-07-22 03:31:35 UTC (rev 6591)
+++ trunk/Catalyst-Plugin-PageCache/Build.PL 2007-07-24 15:06:02 UTC (rev 6592)
@@ -1,14 +0,0 @@
-use strict;
-use Module::Build;
-
-my $build = Module::Build->new(
- create_makefile_pl => 'passthrough',
- license => 'perl',
- module_name => 'Catalyst::Plugin::PageCache',
- requires => { 'Catalyst::Runtime' => '0' },
- create_makefile_pl => 'passthrough',
- test_files => [
- glob('t/*.t')
- ]
-);
-$build->create_build_script;
Modified: trunk/Catalyst-Plugin-PageCache/Changes
===================================================================
--- trunk/Catalyst-Plugin-PageCache/Changes 2007-07-22 03:31:35 UTC (rev 6591)
+++ trunk/Catalyst-Plugin-PageCache/Changes 2007-07-24 15:06:02 UTC (rev 6592)
@@ -1,5 +1,10 @@
Revision history for Perl extension Catalyst::Plugin::PageCache
+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.
Deleted: trunk/Catalyst-Plugin-PageCache/MANIFEST
===================================================================
--- trunk/Catalyst-Plugin-PageCache/MANIFEST 2007-07-22 03:31:35 UTC (rev 6591)
+++ trunk/Catalyst-Plugin-PageCache/MANIFEST 2007-07-24 15:06:02 UTC (rev 6592)
@@ -1,20 +0,0 @@
-Build.PL
-Changes
-lib/Catalyst/Plugin/PageCache.pm
-Makefile.PL
-MANIFEST This list of files
-META.yml
-README
-t/01use.t
-t/02pod.t
-t/03podcoverage.t
-t/04cache.t
-t/05expires.t
-t/06auto_cache.t
-t/07set_http_headers.t
-t/08params.t
-t/09datetime.t
-t/10options.t
-t/11nocache.t
-t/lib/TestApp.pm
-t/lib/TestApp/C/Cache.pm
Modified: trunk/Catalyst-Plugin-PageCache/Makefile.PL
===================================================================
--- trunk/Catalyst-Plugin-PageCache/Makefile.PL 2007-07-22 03:31:35 UTC (rev 6591)
+++ trunk/Catalyst-Plugin-PageCache/Makefile.PL 2007-07-24 15:06:02 UTC (rev 6592)
@@ -1,31 +1,10 @@
-# Note: this file was auto-generated by Module::Build::Compat version 0.03
-
- unless (eval "use Module::Build::Compat 0.02; 1" ) {
- print "This module requires Module::Build to install itself.\n";
-
- require ExtUtils::MakeMaker;
- my $yn = ExtUtils::MakeMaker::prompt
- (' Install Module::Build now from CPAN?', 'y');
-
- unless ($yn =~ /^y/i) {
- die " *** Cannot install without Module::Build. Exiting ...\n";
- }
-
- require Cwd;
- require File::Spec;
- require CPAN;
-
- # Save this 'cause CPAN will chdir all over the place.
- my $cwd = Cwd::cwd();
-
- CPAN::Shell->install('Module::Build::Compat');
- CPAN::Shell->expand("Module", "Module::Build::Compat")->uptodate
- or die "Couldn't install Module::Build, giving up.\n";
-
- chdir $cwd or die "Cannot chdir() back to $cwd: $!";
- }
- eval "use Module::Build::Compat 0.02; 1" or die $@;
-
- Module::Build::Compat->run_build_pl(args => \@ARGV);
- require Module::Build;
- Module::Build::Compat->write_makefile(build_class => 'Module::Build');
+use inc::Module::Install 0.65;
+
+name 'Catalyst-Plugin-PageCache';
+all_from 'lib/Catalyst/Plugin/PageCache.pm';
+
+requires 'Catalyst::Runtime' => '0';
+requires 'Test::More';
+
+auto_install;
+WriteAll;
Modified: trunk/Catalyst-Plugin-PageCache/README
===================================================================
--- trunk/Catalyst-Plugin-PageCache/README 2007-07-22 03:31:35 UTC (rev 6591)
+++ trunk/Catalyst-Plugin-PageCache/README 2007-07-24 15:06:02 UTC (rev 6592)
@@ -4,7 +4,7 @@
SYNOPSIS
use Catalyst;
MyApp->setup( qw/Cache::FileCache PageCache/ );
-
+
MyApp->config->{page_cache} = {
expires => 300,
set_http_headers => 1,
@@ -17,9 +17,19 @@
# 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
@@ -50,12 +60,12 @@
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
@@ -66,7 +76,7 @@
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
@@ -74,9 +84,11 @@
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 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.
METHODS
cache_page
@@ -90,17 +102,110 @@
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.
+
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,
@@ -118,8 +223,11 @@
Catalyst::Plugin::Cache::FileCache, Catalyst::Plugin::Cache::Memcached
AUTHOR
- Andy Grundman, "andy at hybridized.org"
+ Andy Grundman, <andy at hybridized.org>
+THANKS
+ Bill Moseley, <mods at hank.org>, for many patches and tests.
+
COPYRIGHT
This program is free software, you can redistribute it and/or modify it
under the same terms as Perl itself.
Modified: trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm
===================================================================
--- trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm 2007-07-22 03:31:35 UTC (rev 6591)
+++ trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm 2007-07-24 15:06:02 UTC (rev 6592)
@@ -4,7 +4,7 @@
use base qw/Class::Accessor::Fast/;
use NEXT;
-our $VERSION = '0.15';
+our $VERSION = '0.16';
# Do we need to cache the current page?
__PACKAGE__->mk_accessors('_cache_page');
@@ -317,6 +317,9 @@
}
$key .= '?' . join( '&', @params );
}
+ elsif ( my $query = $c->req->uri->query ) {
+ $key .= '?' . $query;
+ }
$c->_page_cache_key( $key );
@@ -543,6 +546,20 @@
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 KNOWN ISSUES
It is not currently possible to cache pages served from the Static plugin. If you're concerned
Modified: trunk/Catalyst-Plugin-PageCache/t/04cache.t
===================================================================
--- trunk/Catalyst-Plugin-PageCache/t/04cache.t 2007-07-22 03:31:35 UTC (rev 6591)
+++ trunk/Catalyst-Plugin-PageCache/t/04cache.t 2007-07-24 15:06:02 UTC (rev 6592)
@@ -12,7 +12,7 @@
eval "use Catalyst::Plugin::Cache::FileCache";
plan $@
? ( skip_all => 'needs Catalyst::Plugin::Cache::FileCache for testing' )
- : ( tests => 18 );
+ : ( tests => 20 );
}
# remove previous cache
@@ -60,3 +60,7 @@
# cache should have expired
ok( $res = request('http://localhost/cache/count/2'), 'request ok' );
is( $res->content, 7, 'count after cache expired is 7' );
+
+# test cache of a page with a parameter-less query string
+ok( $res = request('http://localhost/cache/count/2?foo'), 'request ok' );
+is( $res->content, 8, 'count after query string is 8' );
More information about the Catalyst-commits
mailing list