Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kianmeng/role-cache-lru
Cache::LRU role for Moo related classes
https://github.com/kianmeng/role-cache-lru
cache lru moo perl
Last synced: about 1 month ago
JSON representation
Cache::LRU role for Moo related classes
- Host: GitHub
- URL: https://github.com/kianmeng/role-cache-lru
- Owner: kianmeng
- License: other
- Created: 2019-02-08T12:56:40.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-04T02:19:42.000Z (over 5 years ago)
- Last Synced: 2024-10-19T15:15:37.234Z (2 months ago)
- Topics: cache, lru, moo, perl
- Language: Perl
- Size: 17.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changes
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[![Cpan license](https://img.shields.io/cpan/l/Role-Cache-LRU.svg)](https://metacpan.org/release/Role-Cache-LRU)
[![Cpan version](https://img.shields.io/cpan/v/Role-Cache-LRU.svg)](https://metacpan.org/release/Role-Cache-LRU)# NAME
Role::Cache::LRU - LRU caching role for Moo class.
# SYNOPSIS
package MyPackage;
use Moo;
with 'Role::Cache::LRU';my $mp = MyPackage->new;
$mp->set_cache('foo', {bar => 1});
$mp->get_cache('foo');# DESCRIPTION
Role::Cache::LRU is a Moo's role that provides LRU caching based on
[Cache::LRU](https://metacpan.org/pod/Cache::LRU).# DEVELOPMENT
Source repository at [https://github.com/kianmeng/role-cache-lru](https://github.com/kianmeng/role-cache-lru).
How to contribute? Follow through the [CONTRIBUTING.md](https://github.com/kianmeng/role-cache-lru/blob/master/CONTRIBUTING.md) document to setup your development environment.
# METHODS
## set\_cache($key, $item)
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\_cache($key)
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\_cache\_size($max)
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\_cache\_size()
Get the maximum cache size. The default maximum value is 1024.
my $mp = MyPackage->new;
print $mp->get_cache_size();
# 1024# AUTHOR
Kian Meng, Ang
# COPYRIGHT AND LICENSE
This software is Copyright (c) 2019 Kian Meng, Ang.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
# SEE ALSO
[Cache::LRU](https://metacpan.org/pod/Cache::LRU)