NAME
Method::Cached - The return value of the method is cached to your storage
SYNOPSIS
package Foo;
use Method::Cached;
sub message :Cached(5) { join ':', @_, time, rand }
package main;
use Perl6::Say;
say Foo::message(1); # 1222333848
sleep 1;
say Foo::message(1); # 1222333848
say Foo::message(5); # 1222333849
DESCRIPTION
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.
SETTING OF CACHED DOMAIN
In beginning logic or the start-up script:
use Method::Cached;
Method::Cached->default_domain({
storage_class => 'Cache::FastMmap',
});
Method::Cached->set_domain(
'some-namespace' => {
storage_class => 'Cache::Memcached::Fast',
storage_args => [
{
# Parameter of constructor of class that uses it for cashe
servers => [ '192.168.254.2:11211', '192.168.254.3:11211' ],
...
},
],
},
);
DEFINITION OF METHODS
This function is mounting used as an attribute of the method.
- :Cached ( DOMAIN_NAME, EXPIRES, [, KEY_RULE, ...] )
-
The cached rule is defined specifying the domain name.
sub message :Cached('some-namespace', 60 * 5, LIST) { ... }
- :Cached ( EXPIRES, [, KEY_RULE, ...] )
-
When the domain name is omitted, the domain of default is used.
sub message :Cached(60 * 30, LIST) { ... }
RULE TO GENERATE KEY
- LIST
- HASH
- SELF_SHIFT
- PER_OBJECT
OPTIONAL, RULE TO GENERATE KEY
use Method::Cached;
use Method::Cached::KeyRule::Serialize;
- SERIALIZE
- SELF_CODED
METHODS
AUTHOR
Satoshi Ohkubo <s.ohkubo@gmail.com>
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.