CGI::Application::Plugin::Cache::Adaptive - Provide cacheable to method using attribute.
version 0.03
package MyApp; use base qw(CGI::Application); use CGI::Application::Plugin::Cache::Adaptive; use Cache::FileCache; sub setup { my $self = shift; $self->start_mode('default'); $self->run_modes( 'default' => 'do_default' ); $self->cache_adaptive({ backend => Cache::FileCache->new({ namespace => 'html_cache', max_size => 10 * 1024 * 1024, }), expires_min => 3, expires_max => 60, check_load => sub { my $entry = shift; int($entry->{process_time} * 2) - 1; }, }); } sub do_default : Cacheable(qw/path path_info query/) { sleep 10; return "test"; }
This module provides adaptive cache to specified method by 'Cacheable' attribute. Cache mechanism depends on Cache::Adaptive.
Cacheable attribute is able to accept some arguments. The arguments effects Cache::Adaptive behavior.
The arguments must be array or hash reference. See below the arguments detail.
Example,
sub do_something : Cacheable(qw/path session/) { # process by user }
Array arguments accepts 4 items,
Add path(script_name) to cache key salt.
Add query string to cache key salt.
Add path_info to cache key salt.
Add session_id to cache key salt.
sub do_something : Cacheable({key_from => [qw/path path_info/], label => 'memcached'}) { # some process }
Hash reference accepts 2 original key and any key permitted by Cache::Adaptive's access method.
Same as array arguments. See "Array arguments" in CGI::Application::Plugin::Cache::Adaptive.
Change cache profile to specified labeled cache object. See "cache_adaptive($label)" in Cache::Adaptive.
Alias cache_adaptive('default'). See "cache_adaptive($label)" in CGI::Application::Plugin::Cache::Adaptive
Get Cache::Adaptive object by label.
Set Cache::Adaptive object to 'default' label. The $hash_ref is Cache::Adaptive's new parameter.
Set Cache::Adaptive or that inheritance object to 'default' label.
Set Cache::Adaptive object to specified label. The $hash_ref is Cache::Adaptive's new parameter.
Set Cache::Adaptive or that inheritance object to specified label.
Provide cacheable to specified method. See Attribute::Handlers
Toru Yamaguchi, <zigorou@cpan.org>
<zigorou@cpan.org>
Kazuho Oku, <kazuhooku@gmail.com>
<kazuhooku@gmail.com>
Please report any bugs or feature requests to bug-cgi-application-plugin-cache-adaptive@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-cgi-application-plugin-cache-adaptive@rt.cpan.org
Copyright 2007 Toru Yamaguchi, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install CGI::Application::Plugin::Cache::Adaptive, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CGI::Application::Plugin::Cache::Adaptive
CPAN shell
perl -MCPAN -e shell install CGI::Application::Plugin::Cache::Adaptive
For more information on module installation, please visit the detailed CPAN module installation guide.