Cache-Ref
view release on metacpan or search on metacpan
lib/Cache/Ref/CAR/Base.pm view on Meta::CPAN
package Cache::Ref::CAR::Base;
BEGIN {
$Cache::Ref::CAR::Base::AUTHORITY = 'cpan:NUFFIN';
}
BEGIN {
$Cache::Ref::CAR::Base::VERSION = '0.04';
}
# ABSTRACT: base clase for CAR and CART
use Moose::Role;
# TODO
# this needs lot of cleanup but I ran out of motivation. it works, though.
#
# the circular buffers should finish being implemented using the doubly linked
# list role
#
# CART needs a bunch of simplifications in the code
#
# the various linked list APIs should probably be consolidated to respect the
# MFU bit, with _move_to_history, _restore_from_history etc checking that
# instead of having two methods per each
use namespace::autoclean;
sub REF_BIT () { 0x01 }
sub MFU_BIT () { 0x02 }
sub LONG_TERM_BIT () { 0x04 }
requires qw(
_mru_history_too_big
_mfu_history_too_big
_restore_from_mfu_history
_restore_from_mru_history
_clear_additional
_decrease_mru_target_size
_increase_mru_target_size
);
with (
qw(
Cache::Ref::Role::API
Cache::Ref::Role::Index
),
map {
('Cache::Ref::Role::WithDoublyLinkedList' => { # FIXME can it just be circular too?
name => $_,
value_offset => 1, # the cache key
next_offset => 3,
prev_offset => 4,
}),
} qw(_mru_history _mfu_history), # b1, b2
);
sub _next { $_[1][3] }
sub _set_next {
my ( $self, $node, $next ) = @_;
$node->[3] = $next;
}
sub _prev { $_[1][4] }
sub _set_prev {
my ( $self, $node, $prev ) = @_;
$node->[4] = $prev;
}
has size => (
isa => "Int",
is => "ro",
required => 1,
);
foreach my $pool (qw(mfu mru)) { # t1, t2
has "_$pool" => ( is => "rw" ); # circular linked list tail
foreach my $counter (qw(size history_size)) {
has "_${pool}_$counter" => (
#traits => [qw(Counter)], # too slow, not inlined, nytprof gives it about 60% of runtime =P
is => "ro",
writer => "_set_${pool}_$counter",
default => sub { 0 },
( run in 1.000 second using v1.01-cache-2.11-cpan-39bf76dae61 )