Cache-Sliding
view release on metacpan or search on metacpan
lib/Cache/Sliding.pm view on Meta::CPAN
package Cache::Sliding;
use 5.010001;
use warnings;
use strict;
use utf8;
use Carp;
our $VERSION = 'v2.0.1';
use Scalar::Util qw( weaken );
use EV;
sub new {
my ($class, $expire_after) = @_;
my $self = {
L1 => {},
L2 => {},
t => undef,
};
weaken(my $this = $self);
$self->{t} = EV::timer $expire_after, $expire_after, sub { if ($this) {
$this->{L2} = $this->{L1};
$this->{L1} = {};
} };
return bless $self, $class;
}
sub get {
my ($self, $key) = @_;
if (exists $self->{L1}{$key}) {
( run in 0.323 second using v1.01-cache-2.11-cpan-65fba6d93b7 )