NAME
Cache::Memory::Simple::ID - Yet another on memory cache for ID key
SYNOPSIS
use Cache::Memory::Simple::ID;
use feature qw/state/;
sub get_user_info {
my ($class, $user_id) = @_;
state $user_cache = Cache::Memory::Simple::ID->new();
$user_cache->get_or_set(
$user_id, sub {
Storage->get($user_id) # slow operation
}, 10 # cache in 10 seconds
);
}
DESCRIPTION
Cache::Memory::Simple::ID was optimised an ID(integer) key for caching. It is bit faster than Cache::Memory::Simple which uses HASH for caching. And Cache::Memory::Simple::ID is friendly with memory.
To check more detail: benchmark/*
of this distribution
CAVEAT
You can use ONLY an integer key as cache key.
METHODS
my $obj = Cache::Memory::Simple::ID->new()
-
Create a new instance.
my $stuff = $obj->get($id);
-
Get a stuff from cache storage by
$id
$obj->set($id, $val, $expiration)
-
Set a stuff for cache.
$obj->get_or_set($id, $code, $expiration)
-
Get a cache value for $id if it's already cached. If it's not cached then, run $code and cache $expiration seconds and return the value.
$obj->delete($id)
-
Delete key from cache.
$obj->remove($id)
-
Alias for 'delete' method.
$obj->purge()
-
Purge expired data.
This module does not purge expired data automatically. You need to call this method if you need.
$obj->delete_all()
-
Remove all data from cache.
$obj->count()
-
Get a count of cache element.
REPOSITORY


Cache::Memory::Simple::ID is hosted on github: http://github.com/bayashi/Cache-Memory-Simple-ID
I appreciate any feedback :D
AUTHOR
Dai Okabayashi <bayashi@cpan.org>
SEE ALSO
LICENSE
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.