Role::Cache::LRU - Add LRU caching to any Moo classes.
package MyPackage; use Moo; use Role::Cache::LRU; my $mp = MyPackage->new; $mp->set_cache('foo', {bar => 1}); $mp->get_cache('foo');
Role::Cache::LRU is a Moo's role that provides LRU caching based on Cache::LRU.
Source repo at https://github.com/kianmeng/role-cache-lru.
How to contribute? Follow through the CONTRIBUTING.md document to setup your development environment.
Add a cache item to the cache. The $key must be a string.
my $mp = MyPackage->new; $mp->set_cache('foo', {bar => 1}); $mp->set_cache('bar', [1, 2, 3]);
Get a cached item based on the $key. If nothing is found, returns undef.
my $mp = MyPackage->new; my $item = $mp->get_cache('fishball'); print $item; # undef
Set the maximum cached size. The $max value must be larger or equal to 1. Adjust this to your available maximum memory in your script.
my $mp = MyPackage->new; $mp->set_cache_size(4096);
Get the maximum cache size. The default maximum value is 1024.
my $mp = MyPackage->new; print $mp->get_cache_size(); # 1024
This software is Copyright (c) 2019 Kian Meng, Ang.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
Kian Meng, Ang <kianmeng@users.noreply.github.com>
Cache::LRU
To install Role::Cache::LRU, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Role::Cache::LRU
CPAN shell
perl -MCPAN -e shell install Role::Cache::LRU
For more information on module installation, please visit the detailed CPAN module installation guide.