line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Autocache::Strategy::Statistics; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4
|
use Any::Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
extends 'Autocache::Strategy'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
510
|
use Autocache; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
8
|
1
|
|
|
1
|
|
3
|
use Autocache::Logger qw(get_logger); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
398
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# base_strategy : underlying strategy that handles storage and expiry - |
12
|
|
|
|
|
|
|
# defaults |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
has 'base_strategy' => ( |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
isa => 'Autocache::Strategy', |
17
|
|
|
|
|
|
|
lazy_build => 1, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
# hashref containing our stats |
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
has 'statistics' => ( |
24
|
|
|
|
|
|
|
is => 'rw', |
25
|
|
|
|
|
|
|
isa => 'HashRef', |
26
|
|
|
|
|
|
|
lazy_build => 1, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# |
30
|
|
|
|
|
|
|
# create REQ |
31
|
|
|
|
|
|
|
# |
32
|
|
|
|
|
|
|
sub create |
33
|
|
|
|
|
|
|
{ |
34
|
65
|
|
|
65
|
0
|
48
|
my ($self,$req) = @_; |
35
|
65
|
|
|
|
|
77
|
get_logger()->debug( "create" ); |
36
|
65
|
|
|
|
|
81
|
++$self->statistics->{create}; |
37
|
65
|
|
|
|
|
205
|
return $self->base_strategy->create( $req ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# |
41
|
|
|
|
|
|
|
# get REQ |
42
|
|
|
|
|
|
|
# |
43
|
|
|
|
|
|
|
sub get |
44
|
|
|
|
|
|
|
{ |
45
|
128
|
|
|
128
|
1
|
92
|
my ($self,$req) = @_; |
46
|
128
|
|
|
|
|
151
|
get_logger()->debug( "get" ); |
47
|
128
|
|
|
|
|
250
|
my $rec = $self->base_strategy->get( |
48
|
|
|
|
|
|
|
$req ); |
49
|
128
|
100
|
|
|
|
127
|
if( $rec ) |
50
|
|
|
|
|
|
|
{ |
51
|
63
|
|
|
|
|
77
|
++$self->statistics->{hit}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else |
54
|
|
|
|
|
|
|
{ |
55
|
65
|
|
|
|
|
83
|
++$self->statistics->{miss}; |
56
|
|
|
|
|
|
|
} |
57
|
128
|
|
|
|
|
127
|
++$self->statistics->{total}; |
58
|
128
|
|
|
|
|
146
|
return $rec; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# |
62
|
|
|
|
|
|
|
# REQ REC |
63
|
|
|
|
|
|
|
# |
64
|
|
|
|
|
|
|
sub set |
65
|
|
|
|
|
|
|
{ |
66
|
65
|
|
|
65
|
1
|
42
|
my ($self,$req,$rec) = @_; |
67
|
65
|
|
|
|
|
87
|
get_logger()->debug( "set " . $rec->name ); |
68
|
65
|
|
|
|
|
168
|
return $self->base_strategy->set( $req, $rec ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# |
72
|
|
|
|
|
|
|
# delete KEY |
73
|
|
|
|
|
|
|
# |
74
|
|
|
|
|
|
|
sub delete |
75
|
|
|
|
|
|
|
{ |
76
|
0
|
|
|
0
|
1
|
0
|
my ($self,$key) = @_; |
77
|
0
|
|
|
|
|
0
|
return $self->base_strategy->delete( $key ); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub clear |
81
|
|
|
|
|
|
|
{ |
82
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
83
|
0
|
|
|
|
|
0
|
return $self->base_strategy->clear; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub _build_base_strategy |
87
|
|
|
|
|
|
|
{ |
88
|
0
|
|
|
0
|
|
0
|
return Autocache->singleton->get_default_strategy(); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _build_statistics |
92
|
|
|
|
|
|
|
{ |
93
|
|
|
|
|
|
|
return { |
94
|
1
|
|
|
1
|
|
5
|
hit => 0, |
95
|
|
|
|
|
|
|
miss => 0, |
96
|
|
|
|
|
|
|
create => 0, |
97
|
|
|
|
|
|
|
total => 0, |
98
|
|
|
|
|
|
|
}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
around BUILDARGS => sub |
102
|
|
|
|
|
|
|
{ |
103
|
|
|
|
|
|
|
my $orig = shift; |
104
|
|
|
|
|
|
|
my $class = shift; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
get_logger()->debug( __PACKAGE__ . " - BUILDARGS" ); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
if( ref $_[0] ) |
109
|
|
|
|
|
|
|
{ |
110
|
|
|
|
|
|
|
my $config = $_[0]; |
111
|
|
|
|
|
|
|
my %args; |
112
|
|
|
|
|
|
|
my $node; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
if( $node = $config->get_node( 'base_strategy' ) ) |
115
|
|
|
|
|
|
|
{ |
116
|
|
|
|
|
|
|
get_logger()->debug( "base strategy node found" ); |
117
|
|
|
|
|
|
|
$args{base_strategy} = Autocache->singleton->get_strategy( $node->value ); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
return $class->$orig( %args ); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
else |
123
|
|
|
|
|
|
|
{ |
124
|
|
|
|
|
|
|
return $class->$orig(@_); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
}; |
127
|
|
|
|
|
|
|
|
128
|
1
|
|
|
1
|
|
4
|
no Any::Moose; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
129
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |