Cache-Ref
view release on metacpan or search on metacpan
lib/Cache/Ref/CART.pm view on Meta::CPAN
package Cache::Ref::CART;
BEGIN {
$Cache::Ref::CART::AUTHORITY = 'cpan:NUFFIN';
}
BEGIN {
$Cache::Ref::CART::VERSION = '0.04';
}
# ABSTRACT: CAR with temporal filtering
use Moose;
use List::Util qw(max min);
use Cache::Ref::CAR::Base ();
use namespace::autoclean;
extends qw(Cache::Ref);
with qw(Cache::Ref::CAR::Base);
has _long_term_utility_size => ( # q
is => "ro",
writer => "_set_long_term_utility_size",
default => 0,
);
has _mru_history_target_size => ( # q
is => "ro",
writer => "_set_mru_history_target_size",
default => 0,
);
sub _inc_long_term_utility_size {
my $self = shift;
$self->_set_long_term_utility_size( $self->_long_term_utility_size + 1 );
}
sub _dec_long_term_utility_size {
my $self = shift;
$self->_set_long_term_utility_size( $self->_long_term_utility_size - 1 );
}
sub _reset_long_term_utility_size {
my $self = shift;
$self->_set_long_term_utility_size(0);
}
sub _reset_mru_history_target_size {
my $self = shift;
$self->_set_mru_history_target_size(0);
}
sub _mru_history_too_big {
my $self = shift;
# only if there's something to purge
return unless $self->_mru_history_size;
# only if we need to purge
return unless $self->_mru_history_size + $self->_mfu_history_size == $self->size + 1;
# purge from here if there's nothing to purge from mfu
return 1 if $self->_mfu_history_size == 0;
# or if the target size is too big
return 1 if $self->_mru_history_size > $self->_mru_history_target_size;
return;
}
sub _mfu_history_too_big {
my $self = shift;
return unless $self->_mfu_history_size;
( run in 0.653 second using v1.01-cache-2.11-cpan-39bf76dae61 )