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 is cache storage for one scalar value with expiration.
Create a new instance.
Get a stuff from cache storage.
Set a stuff to cache.
$expiration is in seconds.
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.
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.