| 1 | package EntityModel::StorageClass::KVStore::Layer::LRU; | ||||||||||||
| 2 | { | ||||||||||||
| 3 | 1 | $EntityModel::StorageClass::KVStore::Layer::LRU::VERSION = '0.102'; | |||||||||||
| 4 | } | ||||||||||||
| 5 | 1 | ▶ | use parent qw(EntityModel::StorageClass::KVStore::Layer); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 1 | ▶ | use Tie::Hash::LRU; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 9 | 0 | my $class = shift; | |||||||||||
| 10 | 0 | my %args = @_; | |||||||||||
| 11 | 0 | my $self = $class->SUPER::new; | |||||||||||
| 12 | 0 | ▶ | tie my %h, 'Tie::Hash::LRU', $args{entries} || 50; | ||||||||||
|
Condition0%0/2
$args{'entries'} || 50
MC/DC0%0/1
$args{'entries'} || 50
$args{'entries'}
Truth table0%0/2
A
A= $args{'entries'}
| |||||||||||||
| 13 | 0 | $self->{cache} = \%h; | |||||||||||
| 14 | 0 | $self | |||||||||||
| 15 | } | ||||||||||||
| 16 | |||||||||||||
| 17 | =head2 lookup | ||||||||||||
| 18 | |||||||||||||
| 19 | Returns the cached value if we have it. Intended to be a low-overhead method for | ||||||||||||
| 20 | interacting with local, nonblocking caches. | ||||||||||||
| 21 | |||||||||||||
| 22 | Takes a single $query parameter which will be the query we're trying to find. | ||||||||||||
| 23 | |||||||||||||
| 24 | Returns an empty list if we don't have an answer in the cache, undef if we | ||||||||||||
| 25 | have an answer and that answer is "no value", otherwise returns whatever | ||||||||||||
| 26 | value we have on file. | ||||||||||||
| 27 | |||||||||||||
| 28 | =cut | ||||||||||||
| 29 | |||||||||||||
| 30 | 0 | ▶ | sub lookup { | ||||||||||
|
Subroutine
lookup: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 31 | 0 | my $self = shift; | |||||||||||
| 32 | 0 | my $k = shift; | |||||||||||
| 33 | 0 | ▶ | return $self->{cache}->{$k} if exists $self->{cache}->{$k}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 34 | 0 | return; | |||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | =head2 store | ||||||||||||
| 38 | |||||||||||||
| 39 | Store a value in the cache. | ||||||||||||
| 40 | |||||||||||||
| 41 | Takes the following parameters: | ||||||||||||
| 42 | |||||||||||||
| 43 | =over 4 | ||||||||||||
| 44 | |||||||||||||
| 45 | =item * $query - query to store under | ||||||||||||
| 46 | |||||||||||||
| 47 | =item * $value - value to store in key (can be undef) | ||||||||||||
| 48 | |||||||||||||
| 49 | =back | ||||||||||||
| 50 | |||||||||||||
| 51 | Returns $self. | ||||||||||||
| 52 | |||||||||||||
| 53 | =cut | ||||||||||||
| 54 | |||||||||||||
| 55 | 0 | ▶ | sub store { | ||||||||||
|
Subroutine
store: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 56 | 0 | my ($self, $k, $v) = @_; | |||||||||||
| 57 | 0 | $self->{cache}->{$k} = $v; | |||||||||||
| 58 | 0 | $self | |||||||||||
| 59 | } | ||||||||||||
| 60 | |||||||||||||
| 61 | 1 | 1; | |||||||||||