File Coverage

blib/lib/Autocache/Strategy/Store/Memory.pm
Criterion Covered Total %
statement 16 22 72.7
branch 2 2 100.0
condition n/a
subroutine 5 7 71.4
pod 4 4 100.0
total 27 35 77.1


line stmt bran cond sub pod time code
1             package Autocache::Strategy::Store::Memory;
2              
3 5     5   29 use Any::Moose;
  5         10  
  5         40  
4              
5             extends 'Autocache::Strategy';
6              
7 5     5   3441 use Autocache::Logger qw(get_logger);
  5         10  
  5         2063  
8              
9             has '_cache' => (
10             is => 'rw',
11             default => sub { {} },
12             init_arg => undef,
13             );
14              
15             #
16             # get REQ
17             #
18             sub get
19             {
20 129     129 1 165 my ($self,$req) = @_;
21 129         277 get_logger()->debug( "get: " . $req->key );
22 129 100       822 return unless exists $self->_cache->{$req->key};
23 62         262 return $self->_cache->{$req->key};
24             }
25              
26             #
27             # set REQ REC
28             #
29             sub set
30             {
31 67     67 1 97 my ($self,$req,$rec) = @_;
32 67         159 get_logger()->debug( "set: " . $req->key );
33 67         486 $self->_cache->{$req->key} = $rec;
34             }
35              
36             #
37             # delete KEY
38             #
39             sub delete
40             {
41 0     0 1   my ($self,$key) = @_;
42 0           get_logger()->debug( "delete: $key" );
43 0           delete $self->_cache->{$key};
44             }
45              
46             #
47             # clear
48             #
49             sub clear
50             {
51 0     0 1   my ($self,$key) = @_;
52 0           get_logger()->debug( "clear" );
53 0           $self->_cache = {};
54             }
55              
56             around BUILDARGS => sub {
57             my $orig = shift;
58             my $class = shift;
59             return $class->$orig();
60             };
61              
62 5     5   30 no Any::Moose;
  5         11  
  5         24  
63             __PACKAGE__->meta->make_immutable;
64              
65             1;