| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Autocache::Strategy::Refresh; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3
|
use Any::Moose; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
extends 'Autocache::Strategy'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
533
|
use Autocache; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
55
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
49
|
|
|
9
|
1
|
|
|
1
|
|
4
|
use Autocache::Logger qw(get_logger); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
42
|
|
|
10
|
1
|
|
|
1
|
|
4
|
use Scalar::Util qw( weaken ); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
592
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# |
|
13
|
|
|
|
|
|
|
# Refresh Strategy - freshen content regularly in the background |
|
14
|
|
|
|
|
|
|
# |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# |
|
17
|
|
|
|
|
|
|
# refresh_age : content older than this in seconds will be refreshed in the |
|
18
|
|
|
|
|
|
|
# background by a work queue |
|
19
|
|
|
|
|
|
|
# |
|
20
|
|
|
|
|
|
|
has 'refresh_age' => ( |
|
21
|
|
|
|
|
|
|
is => 'rw', |
|
22
|
|
|
|
|
|
|
isa => 'Int', |
|
23
|
|
|
|
|
|
|
default => 60, |
|
24
|
|
|
|
|
|
|
); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# |
|
27
|
|
|
|
|
|
|
# base_strategy : underlying strategy that handles storage and expiry - |
|
28
|
|
|
|
|
|
|
# defaults |
|
29
|
|
|
|
|
|
|
# |
|
30
|
|
|
|
|
|
|
has 'base_strategy' => ( |
|
31
|
|
|
|
|
|
|
is => 'ro', |
|
32
|
|
|
|
|
|
|
isa => 'Autocache::Strategy', |
|
33
|
|
|
|
|
|
|
lazy_build => 1, |
|
34
|
|
|
|
|
|
|
); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# |
|
37
|
|
|
|
|
|
|
# work_queue : object that provides a work_queue interface to push refresh |
|
38
|
|
|
|
|
|
|
# jobs on to |
|
39
|
|
|
|
|
|
|
# |
|
40
|
|
|
|
|
|
|
has 'work_queue' => ( |
|
41
|
|
|
|
|
|
|
is => 'ro', |
|
42
|
|
|
|
|
|
|
isa => 'Autocache::WorkQueue', |
|
43
|
|
|
|
|
|
|
lazy_build => 1, |
|
44
|
|
|
|
|
|
|
); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# |
|
47
|
|
|
|
|
|
|
# create REQ |
|
48
|
|
|
|
|
|
|
# |
|
49
|
|
|
|
|
|
|
sub create |
|
50
|
|
|
|
|
|
|
{ |
|
51
|
0
|
|
|
0
|
0
|
|
my ($self,$req) = @_; |
|
52
|
0
|
|
|
|
|
|
get_logger()->debug( "create" ); |
|
53
|
0
|
|
|
|
|
|
return $self->base_strategy->create( $req ); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub get |
|
57
|
|
|
|
|
|
|
{ |
|
58
|
0
|
|
|
0
|
1
|
|
my ($self,$req) = @_; |
|
59
|
0
|
|
|
|
|
|
get_logger()->debug( "get" ); |
|
60
|
0
|
|
|
|
|
|
my $rec = $self->base_strategy->get( $req ); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# |
|
64
|
|
|
|
|
|
|
# TODO - add min refresh time to stop cache stampede for shared caches |
|
65
|
|
|
|
|
|
|
# |
|
66
|
0
|
0
|
0
|
|
|
|
if( $rec and ( $rec->age > $self->refresh_age ) ) |
|
67
|
|
|
|
|
|
|
{ |
|
68
|
0
|
|
|
|
|
|
get_logger()->debug( "record age : " . $rec->age ); |
|
69
|
0
|
|
|
|
|
|
get_logger()->debug( "refresh age : " . $self->refresh_age ); |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$self->work_queue->push( $self->_refresh_task( $req, $rec ) ); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
return $rec; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# |
|
78
|
|
|
|
|
|
|
# REQ REC |
|
79
|
|
|
|
|
|
|
# |
|
80
|
|
|
|
|
|
|
sub set |
|
81
|
|
|
|
|
|
|
{ |
|
82
|
0
|
|
|
0
|
1
|
|
my ($self,$req,$rec) = @_; |
|
83
|
0
|
|
|
|
|
|
get_logger()->debug( "set " . $req->name ); |
|
84
|
0
|
|
|
|
|
|
return $self->base_strategy->set( $req, $rec ); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _refresh_task |
|
88
|
|
|
|
|
|
|
{ |
|
89
|
0
|
|
|
0
|
|
|
my ($self,$req,$rec) = @_; |
|
90
|
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
get_logger()->debug( "_refresh_task " . $rec->name ); |
|
92
|
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
weaken $self; |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
return sub |
|
96
|
|
|
|
|
|
|
{ |
|
97
|
0
|
|
|
0
|
|
|
get_logger()->debug( "refreshing record: " . $rec->to_string ); |
|
98
|
0
|
|
|
|
|
|
my $fresh_rec = $self->create( $req ); |
|
99
|
0
|
|
|
|
|
|
$self->set( $fresh_rec ); |
|
100
|
0
|
|
|
|
|
|
}; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# |
|
104
|
|
|
|
|
|
|
# delete KEY |
|
105
|
|
|
|
|
|
|
# |
|
106
|
|
|
|
|
|
|
sub delete |
|
107
|
|
|
|
|
|
|
{ |
|
108
|
0
|
|
|
0
|
1
|
|
my ($self,$key) = @_; |
|
109
|
0
|
|
|
|
|
|
return $self->base_strategy->delete( $key ); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub clear |
|
113
|
|
|
|
|
|
|
{ |
|
114
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
|
115
|
0
|
|
|
|
|
|
return $self->base_strategy->clear; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub _build_base_strategy |
|
119
|
|
|
|
|
|
|
{ |
|
120
|
0
|
|
|
0
|
|
|
return Autocache->singleton->get_default_strategy(); |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub _build_work_queue |
|
124
|
|
|
|
|
|
|
{ |
|
125
|
0
|
|
|
0
|
|
|
return Autocache->singleton->get_work_queue(); |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
around BUILDARGS => sub |
|
129
|
|
|
|
|
|
|
{ |
|
130
|
|
|
|
|
|
|
my $orig = shift; |
|
131
|
|
|
|
|
|
|
my $class = shift; |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
get_logger()->debug( __PACKAGE__ . " - BUILDARGS" ); |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
if( ref $_[0] ) |
|
136
|
|
|
|
|
|
|
{ |
|
137
|
|
|
|
|
|
|
my $config = $_[0]; |
|
138
|
|
|
|
|
|
|
my %args; |
|
139
|
|
|
|
|
|
|
my $node; |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
if( $node = $config->get_node( 'base_strategy' ) ) |
|
142
|
|
|
|
|
|
|
{ |
|
143
|
|
|
|
|
|
|
get_logger()->debug( "base strategy node found" ); |
|
144
|
|
|
|
|
|
|
$args{base_strategy} = Autocache->singleton->get_strategy( $node->value ); |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
if( $node = $config->get_node( 'refresh_age' ) ) |
|
148
|
|
|
|
|
|
|
{ |
|
149
|
|
|
|
|
|
|
get_logger()->debug( "refresh age node found" ); |
|
150
|
|
|
|
|
|
|
$args{refresh_age} = $node->value; |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
return $class->$orig( %args ); |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
else |
|
156
|
|
|
|
|
|
|
{ |
|
157
|
|
|
|
|
|
|
return $class->$orig(@_); |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
}; |
|
160
|
|
|
|
|
|
|
|
|
161
|
1
|
|
|
1
|
|
5
|
no Any::Moose; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
4
|
|
|
162
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
1; |