Class::Method::Cache::FastMmap - Cache method results using Cache::FastMmap
version v0.3.2
package MyClass; use Class::Method::Cache::FastMmap; sub my_method { ... } cache 'my_method' => ( serializer => 'storable', expire_time => '1h', );
This package allows you to easily cache the results of a method call using Cache::FastMmap.
cache
cache $method => %options;
This wraps the $method with a function that caches the return value.
$method
It assumes that the method returns a defined scalar value and that the method arguments are serialisable.
The %options are as follows:
%options
is used to specify a different (shared) cache. You may use another caching class, so long as it provides get and set methods.
get
set
Added v0.2.0.
key_cb
is used to provide a custom key-generation function. If none is specified, then Object::Signature is used.
The function should expect a single argument with an array reference corresponding to the original method call parameters:
$key_cb->( [ $self, @_ ] );
prefix
This is the prefix too prepend to the key. It defaults to the class and method name when the "cache" is specified, or an empty string otherwise.
Remaining %options are passed to the constructor for Cache::FastMmap.
As of v0.3.0, you can import the cache method with a different namme:
use Class::Method::Cache::FastMmap "cache" => { -as => "memoize" }; sub my_method { ... } memoize 'my_method' => ( serializer => 'storable', expire_time => '1h', );
Undefined results are not cached. So if your method returns undef on failure, then it never cache that result.
undef
Cache::FastMmap
Object::Signature
The development version is on github at https://github.com/robrwo/Class-Method-Cache-FastMmap and may be cloned from git://github.com/robrwo/Class-Method-Cache-FastMmap.git
Please report any bugs or feature requests on the bugtracker website https://github.com/robrwo/Class-Method-Cache-FastMmap/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
Robert Rothenberg <rrwo@cpan.org>
Some development of this module was sponsored by Science Photo Library https://www.sciencephoto.com.
This software is Copyright (c) 2018 by Robert Rothenberg.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install Class::Method::Cache::FastMmap, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Method::Cache::FastMmap
CPAN shell
perl -MCPAN -e shell install Class::Method::Cache::FastMmap
For more information on module installation, please visit the detailed CPAN module installation guide.