Cache::Memory::Simple::Scalar - Cache one scalar value
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 ); }
Cache::Memory::Simple::Scalar is cache storage for one scalar value with expiration.
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.
Tokuhiro Matsuno <tokuhirom AAJKLFJEF@ GMAIL COM>
Copyright (C) Tokuhiro Matsuno
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Cache::Memory::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Cache::Memory::Simple
CPAN shell
perl -MCPAN -e shell install Cache::Memory::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.