Method::Cached - The return value of the method is cached to your storage
package Foo; use Method::Cached; sub cached :Cached { time . rand } sub no_cached { time . rand } package main; my $test1 = { cached => Foo->cached, no_cached => Foo->no_cached }; sleep 1; # It is preferable that time passes in this test my $test2 = { cached => Foo->cached, no_cached => Foo->no_cached }; is $test1->{cached}, $test2->{cached}; isnt $test1->{no_cached}, $test2->{no_cached};
Method::Cached offers the following mechanisms:
The return value of the method is stored in storage, and the value stored when being execute it next time is returned.
In beginning logic or the start-up script:
use Method::Cached::Manager -default => { class => 'Cache::FastMmap' }, -domains => { 'some-namespace' => { class => 'Cache::Memcached::Fast', args => [ ... ] }, }, ;
For more documentation on setting of cached domain, see Method::Cached::Manager.
This function is mounting used as an attribute of the method.
The cached rule is defined specifying the domain name.
sub message :Cached('some-namespace', 60 * 5, LIST) { ... }
When the domain name is omitted, the domain of default is used.
sub message :Cached(60 * 5, LIST) { ... }
use Method::Cached::KeyRule::Serialize;
Satoshi Ohkubo <s.ohkubo@gmail.com>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Method::Cached, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Method::Cached
CPAN shell
perl -MCPAN -e shell install Method::Cached
For more information on module installation, please visit the detailed CPAN module installation guide.