NAME

Cache::Scalar::WithExpiry - Cache one scalar value with expiry

SYNOPSIS

use Cache::Scalar::WithExpiry;
use feature qw/state/;


state $cache = Cache::Scalar::WithExpiry->new();
my ($value, $expiry_epoch) = $cache->get_or_set(sub {
    my $val          = Storage->get;
    my $expiry_epoch = time + 20;
    return ($val, $expiry_epoch); # cache in 20 seconds
});

DSL interface

use Cache::Scalar::WithExpiry;


my ($value, $expiry_epoch) = cache_with_expiry {
    my $val          = Storage->get;
    my $expiry_epoch = time + 20;
    return ($val, $expiry_epoch); # cache in 20 seconds
};

DESCRIPTION

Cache::Scalar::WithExpiry is cache storage for one scalar value with expiry epoch.

METHODS

EXPORT FUNCTION

THANKS TO

tokuhirom. Most code of this module is steal from his Cache::Memory::Simple::Scalar.

LICENSE

Copyright (C) Songmu.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Songmu y.songmu@gmail.com