NAME
Cache::Memory::Simple::Scalar - Cache one scalar value
SYNOPSIS
use Cache::Memory::Simple::Scalar;
use feature qw/state/;
sub get_stuff {
my ($class, $key) = @_;
state $cache = Cache::Memory::Simple::Scalar->new();
$cache->get_or_set(
sub {
Storage->get($key) # slow operation
}, 10 # cache in 10 seconds
);
}
DESCRIPTION
Cache::Memory::Simple::Scalar is cache storage for one scalar value with expiration.
METHODS
my $obj = Cache::Memory::Simple::Scalar->new()
-
Create a new instance.
my $stuff = $obj->get();
-
Get a stuff from cache storage.
$obj->set($val, $expiration)
-
Set a stuff to cache.
$expiration is in seconds.
$obj->get_or_set($code, $expiration)
-
Get a cache value if it's already cached. If it's not cached then, run $code and cache $expiration seconds and return the value.
$obj->delete()
-
Delete cache from cache.
AUTHOR
Tokuhiro Matsuno <tokuhirom AAJKLFJEF@ GMAIL COM>
SEE ALSO
LICENSE
Copyright (C) Tokuhiro Matsuno
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.