[Catalyst-commits] r13685 -
trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin
timbunce at dev.catalyst.perl.org
timbunce at dev.catalyst.perl.org
Wed Nov 3 11:17:38 GMT 2010
Author: timbunce
Date: 2010-11-03 11:17:38 +0000 (Wed, 03 Nov 2010)
New Revision: 13685
Modified:
trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm
Log:
Renamed $config_PageCache to $pc_config.
Modified: trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm
===================================================================
--- trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm 2010-11-03 11:10:34 UTC (rev 13684)
+++ trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm 2010-11-03 11:17:38 UTC (rev 13685)
@@ -46,21 +46,20 @@
return unless ( $c->can( 'cache' ) );
- my $config_PageCache = $c->config->{'Plugin::PageCache'};
+ my $pc_config = $c->config->{'Plugin::PageCache'};
+ my $is_debug = $pc_config->{debug};
# Warn if index was disabled
- if ( $config_PageCache->{disable_index} ) {
- $c->log->warn("Warning: clear_cached_page($uri) did not clear the cache, disable_index is set");
+ if ( $pc_config->{disable_index} ) {
+ $c->log->warn("clear_cached_page($uri) did not clear the cache because disable_index is set");
return;
}
- my $is_debug = $config_PageCache->{debug};
-
my $removed = 0;
my $cache = $c->cache; # curry the cache just once, here
- my $index = $cache->get( $config_PageCache->{index_page_key} ) || {};
+ my $index = $cache->get( $pc_config->{index_page_key} ) || {};
foreach my $key ( keys %{$index} ) {
if ( $key =~ /^(?::[^:]+:)?$uri$/xms ) {
@@ -72,21 +71,16 @@
}
}
- if ( $removed ) {
- $cache->set(
- $config_PageCache->{index_page_key},
- $index,
- $config_PageCache->{no_expire}
- );
- }
+ $cache->set( $pc_config->{index_page_key}, $index, $pc_config->{no_expire} )
+ if $removed;
}
# return the time that the item should expire
sub _get_page_cache_expiration_time {
my ($c, $options) = @_;
- my $config_PageCache = $c->config->{'Plugin::PageCache'};
- my $is_debug = $config_PageCache->{debug};
+ my $pc_config = $c->config->{'Plugin::PageCache'};
+ my $is_debug = $pc_config->{debug};
my $expires;
@@ -103,9 +97,9 @@
# }
# If all else fails, fallback to the default 'expires' configuration value.
else {
- $c->log->debug("expires in default $config_PageCache->{expires}s")
+ $c->log->debug("expires in default $pc_config->{expires}s")
if $is_debug;
- $expires = time() + $config_PageCache->{expires};
+ $expires = time() + $pc_config->{expires};
}
return $expires;
@@ -120,14 +114,14 @@
return $c->next::method(@_)
unless $c->req->method =~ m/^(?:GET|HEAD)$/;
- my $config_PageCache = $c->config->{'Plugin::PageCache'};
+ my $pc_config = $c->config->{'Plugin::PageCache'};
- my $hook_name = $config_PageCache->{cache_dispatch_hook} || $config_PageCache->{cache_hook};
+ my $hook_name = $pc_config->{cache_dispatch_hook} || $pc_config->{cache_hook};
my $hook = $hook_name ? $c->can($hook_name) : undef;
return $c->next::method(@_) if ( $hook && !$c->$hook() );
return $c->next::method(@_)
- if ( $config_PageCache->{auto_check_user}
+ if ( $pc_config->{auto_check_user}
&& $c->can('user_exists')
&& $c->user_exists);
@@ -143,7 +137,7 @@
# Time to remove page from cache?
if ( $data->{expire_time} && $data->{expire_time} <= time ) {
- if ( my $busy_lock = $config_PageCache->{busy_lock} ) {
+ if ( my $busy_lock = $pc_config->{busy_lock} ) {
# Extend the expiration time for others while
# this caller refreshes the cache
$data->{expire_time} = time() + $busy_lock;
@@ -151,19 +145,19 @@
$cache->set( $key, $data );
$c->log->debug( "$key has expired, being refreshed for $busy_lock seconds" )
- if ($config_PageCache->{debug});
+ if ($pc_config->{debug});
}
else {
$c->log->debug( "Expiring $key from page cache" )
- if ($config_PageCache->{debug});
+ if ($pc_config->{debug});
$cache->remove( $key );
- if ( !$config_PageCache->{disable_index} ) {
- my $index = $cache->get( $config_PageCache->{index_page_key} ) || {};
+ if ( !$pc_config->{disable_index} ) {
+ my $index = $cache->get( $pc_config->{index_page_key} ) || {};
delete $index->{$key};
- $cache->set( $config_PageCache->{index_page_key}, $index,
- $config_PageCache->{no_expire});
+ $cache->set( $pc_config->{index_page_key}, $index,
+ $pc_config->{no_expire});
}
}
@@ -173,7 +167,7 @@
$c->log->debug("Serving $key from page cache, expires in "
. ($data->{expire_time} - time)
. " seconds")
- if ($config_PageCache->{debug});
+ if ($pc_config->{debug});
$c->_page_cache_used( 1 );
@@ -222,9 +216,9 @@
sub _set_page_cache_headers {
my ( $c, $data ) = @_;
my $headers = $c->res->headers;
- my $config_PageCache = $c->config->{'Plugin::PageCache'};
+ my $pc_config = $c->config->{'Plugin::PageCache'};
- if ( $config_PageCache->{cache_headers} ) {
+ if ( $pc_config->{cache_headers} ) {
for my $header_key ( keys %{ $data->{headers} || {} } ) {
$headers->header(
$header_key => $data->{headers}->{$header_key}
@@ -232,7 +226,7 @@
}
}
- return unless $config_PageCache->{set_http_headers};
+ return unless $pc_config->{set_http_headers};
if ( exists $data->{expires} ) {
@@ -267,14 +261,14 @@
# never cache POST requests
return $c->next::method(@_) if ( $c->req->method eq "POST" );
- my $config_PageCache = $c->config->{'Plugin::PageCache'};
+ my $pc_config = $c->config->{'Plugin::PageCache'};
- my $hook_name = $config_PageCache->{cache_dispatch_hook} || $config_PageCache->{cache_hook};
+ my $hook_name = $pc_config->{cache_dispatch_hook} || $pc_config->{cache_hook};
my $hook = $hook_name ? $c->can($hook_name) : undef;
return $c->next::method(@_) if ( $hook && !$c->$hook() );
return $c->next::method(@_)
- if ( $config_PageCache->{auto_check_user}
+ if ( $pc_config->{auto_check_user}
&& $c->can('user_exists')
&& $c->user_exists);
return $c->next::method(@_) if ( scalar @{ $c->error } );
@@ -284,7 +278,7 @@
return $c->next::method(@_) if ( $c->_page_cache_used );
if (!$c->_cache_page
- && scalar @{ $config_PageCache->{auto_cache} })
+ && scalar @{ $pc_config->{auto_cache} })
{
# is this page part of the auto_cache list?
@@ -292,12 +286,12 @@
# For performance, this should be moved to setup, and generate a hash.
AUTO_CACHE:
- foreach my $auto (@{ $config_PageCache->{auto_cache} })
+ foreach my $auto (@{ $pc_config->{auto_cache} })
{
next if $auto =~ m/^\d$/;
if ( $path =~ /^$auto$/ ) {
$c->log->debug( "Auto-caching page $path" )
- if ($config_PageCache->{debug});
+ if ($pc_config->{debug});
$c->cache_page;
last AUTO_CACHE;
}
@@ -319,7 +313,7 @@
my ($c, $options) = @_;
my $key = $c->_get_page_cache_key;
- my $config_PageCache = $c->config->{'Plugin::PageCache'};
+ my $pc_config = $c->config->{'Plugin::PageCache'};
my $now = time();
my $headers = $c->res->headers;
@@ -340,9 +334,9 @@
$c->log->debug(
"Caching page $key for ". ($data->{expire_time} - time()) ." seconds"
- ) if ($config_PageCache->{debug});
+ ) if ($pc_config->{debug});
- if ( $config_PageCache->{cache_headers} ) {
+ if ( $pc_config->{cache_headers} ) {
$data->{headers} = {
map { $_ => $headers->header($_) }
$headers->header_field_names
@@ -357,13 +351,13 @@
$c->_set_page_cache_headers( $data ); # don't forget the first time
- if ( !$config_PageCache->{disable_index} ) {
+ if ( !$pc_config->{disable_index} ) {
# Keep an index cache of all pages that have been cached, for use
# with clear_cached_page
- my $index = $cache->get($config_PageCache->{index_page_key}) || {};
+ my $index = $cache->get($pc_config->{index_page_key}) || {};
$index->{$key} = 1;
# Save data in cache
- $cache->set($config_PageCache->{index_page_key}, $index, $config_PageCache->{no_expire});
+ $cache->set($pc_config->{index_page_key}, $index, $pc_config->{no_expire});
}
return $data;
@@ -380,20 +374,20 @@
$c->config->{'Plugin::PageCache'} = delete $c->config->{page_cache};
}
- my $config_PageCache = $c->config->{'Plugin::PageCache'} ||= {};
+ my $pc_config = $c->config->{'Plugin::PageCache'} ||= {};
- $config_PageCache->{auto_cache} ||= [];
- $config_PageCache->{expires} ||= 60 * 5;
- $config_PageCache->{cache_headers} ||= 0;
- $config_PageCache->{set_http_headers} ||= 0;
- $config_PageCache->{disable_index} ||= 0;
- $config_PageCache->{busy_lock} ||= 0;
- $config_PageCache->{debug} ||= $c->debug;
+ $pc_config->{auto_cache} ||= [];
+ $pc_config->{expires} ||= 60 * 5;
+ $pc_config->{cache_headers} ||= 0;
+ $pc_config->{set_http_headers} ||= 0;
+ $pc_config->{disable_index} ||= 0;
+ $pc_config->{busy_lock} ||= 0;
+ $pc_config->{debug} ||= $c->debug;
# default the page key to include the app name to give some measure
# of protection if the cache doesn't have a namespace set.
- $config_PageCache->{index_page_key} = "$c._page_cache_index"
- unless defined $config_PageCache->{index_page_key};
+ $pc_config->{index_page_key} = "$c._page_cache_index"
+ unless defined $pc_config->{index_page_key};
# detect the cache plugin being used and set appropriate
# never-expires syntax
@@ -408,7 +402,7 @@
# Older Cache plugins
if ( $cache->isa('Cache::FileCache') ) {
- $config_PageCache->{no_expire} = "never";
+ $pc_config->{no_expire} = "never";
}
elsif ($cache->isa('Cache::Memcached')
|| $cache->isa('Cache::FastMmap'))
@@ -416,7 +410,7 @@
# Memcached defaults to 'never' when not given an expiration
# In FastMmap, it's not possible to set an expiration
- $config_PageCache->{no_expire} = undef;
+ $pc_config->{no_expire} = undef;
}
}
else {
@@ -522,7 +516,6 @@
$c->clear_cached_page( '/list' );
-
# Expire at a specific time
$c->cache_page( $datetime_object );
@@ -596,10 +589,10 @@
disable_index => 1
-In order to support the C<clear_cached_page> method, PageCache keeps an index of
+To support the C<clear_cached_page> method, PageCache attempts keep an index of
all cached pages. If you don't intend to use C<clear_cached_page>, you may
enable this config option to avoid the overhead of creating and updating the
-cache index. This option is disabled by default.
+cache index. This option is disabled by default (i.e. the page index is enabled).
index_page_key => '...'
More information about the Catalyst-commits
mailing list