line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cache::Moustache; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
41825
|
use 5.005; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
110
|
|
4
|
|
|
|
|
|
|
#use strict; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
BEGIN { |
7
|
2
|
|
|
2
|
|
4
|
$Cache::Moustache::AUTHORITY = 'cpan:TOBYINK'; |
8
|
2
|
|
|
|
|
1735
|
$Cache::Moustache::VERSION = '0.004'; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub isa |
12
|
|
|
|
|
|
|
{ |
13
|
2
|
|
|
2
|
1
|
5
|
my $what = $_[1]; |
14
|
2
|
50
|
|
|
|
58
|
return 1 if { |
15
|
|
|
|
|
|
|
'Cache' => 1, |
16
|
|
|
|
|
|
|
'Cache::Cache' => 1, |
17
|
|
|
|
|
|
|
'Cache::FastMmap' => 1, |
18
|
|
|
|
|
|
|
'Cache::Moustache' => 1, |
19
|
|
|
|
|
|
|
'Cache::Ref' => 1, |
20
|
|
|
|
|
|
|
'CHI' => 1, |
21
|
|
|
|
|
|
|
'Mojo::Cache' => 1, |
22
|
|
|
|
|
|
|
}->{$what}; |
23
|
0
|
|
|
|
|
0
|
return; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new |
27
|
|
|
|
|
|
|
{ |
28
|
3
|
|
|
3
|
1
|
116
|
my ($class, %args) = @_; |
29
|
3
|
100
|
66
|
|
|
23
|
return $class if ref $class && $class->isa(__PACKAGE__); |
30
|
1
|
|
|
|
|
5
|
my %self = map { ;"~~~~$_" => $args{$_} } keys %args; |
|
1
|
|
|
|
|
7
|
|
31
|
1
|
|
50
|
|
|
10
|
$self{'~~~~default_expires_in'} ||= 3600; |
32
|
1
|
|
|
|
|
11
|
bless {%self}, $class; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my %multipliers = ( |
36
|
|
|
|
|
|
|
s => 1, |
37
|
|
|
|
|
|
|
second => 1, |
38
|
|
|
|
|
|
|
seconds => 1, |
39
|
|
|
|
|
|
|
sec => 1, |
40
|
|
|
|
|
|
|
m => 60, |
41
|
|
|
|
|
|
|
minute => 60, |
42
|
|
|
|
|
|
|
minutes => 60, |
43
|
|
|
|
|
|
|
min => 60, |
44
|
|
|
|
|
|
|
h => 3600, |
45
|
|
|
|
|
|
|
hour => 3600, |
46
|
|
|
|
|
|
|
hours => 3600, |
47
|
|
|
|
|
|
|
d => 86400, |
48
|
|
|
|
|
|
|
day => 86400, |
49
|
|
|
|
|
|
|
days => 86400, |
50
|
|
|
|
|
|
|
w => 604800, |
51
|
|
|
|
|
|
|
week => 604800, |
52
|
|
|
|
|
|
|
weeks => 604800, |
53
|
|
|
|
|
|
|
M => 2419200, |
54
|
|
|
|
|
|
|
month => 2419200, |
55
|
|
|
|
|
|
|
months => 2419200, |
56
|
|
|
|
|
|
|
y => 31536000, |
57
|
|
|
|
|
|
|
year => 31536000, |
58
|
|
|
|
|
|
|
years => 31536000, |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _clone |
62
|
|
|
|
|
|
|
{ |
63
|
3
|
|
|
3
|
|
1223
|
require Storable; |
64
|
3
|
|
|
|
|
4027
|
shift; |
65
|
3
|
|
|
|
|
206
|
goto \&Storable::dclone; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub set |
69
|
|
|
|
|
|
|
{ |
70
|
18
|
|
|
18
|
1
|
3000905
|
my ($cache, $key, $data, $expires_in) = @_; |
71
|
18
|
50
|
|
|
|
68
|
return if $key =~ /^~~~~/; |
72
|
|
|
|
|
|
|
|
73
|
18
|
100
|
66
|
|
|
79
|
$data = $cache->_clone($data) if ref $data && $cache->{'~~~~clone_references'}; |
74
|
|
|
|
|
|
|
|
75
|
18
|
100
|
|
|
|
239
|
$expires_in = $cache->{'~~~~default_expires_in'} if !defined $expires_in; |
76
|
|
|
|
|
|
|
|
77
|
18
|
50
|
|
|
|
155
|
if ($expires_in =~ /^(\d*)\s*([A-Za-z]+)$/) |
78
|
|
|
|
|
|
|
{ |
79
|
0
|
|
|
|
|
0
|
($expires_in, my $mult) = ($1, $2); |
80
|
0
|
0
|
0
|
|
|
0
|
$expires_in = 1 unless defined $expires_in && length $expires_in; |
81
|
0
|
|
0
|
|
|
0
|
$expires_in *= ($multipliers{$mult} || $multipliers{lc $mult}); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
18
|
50
|
|
|
|
63
|
my $expires_at = ($expires_in < 0) ? $expires_in : (time + $expires_in); |
85
|
18
|
|
|
|
|
107
|
$cache->{$key} = [$data, $expires_at]; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub get |
89
|
|
|
|
|
|
|
{ |
90
|
14
|
|
|
14
|
1
|
6000415
|
my ($cache, $key) = @_; |
91
|
14
|
50
|
|
|
|
65
|
return if $key =~ /^~~~~/; |
92
|
14
|
100
|
|
|
|
53
|
return unless exists $cache->{$key}; |
93
|
|
|
|
|
|
|
|
94
|
11
|
|
|
|
|
35
|
my $expires_at = $cache->{$key}[1]; |
95
|
11
|
100
|
66
|
|
|
278
|
if ($expires_at >= 0 and $expires_at < time) |
96
|
|
|
|
|
|
|
{ |
97
|
2
|
|
|
|
|
30
|
$cache->remove($key); |
98
|
2
|
|
|
|
|
20
|
return; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
9
|
|
|
|
|
29
|
$cache->{$key}[0]; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub remove |
105
|
|
|
|
|
|
|
{ |
106
|
4
|
|
|
4
|
1
|
76
|
my ($cache, $key) = @_; |
107
|
4
|
50
|
|
|
|
18
|
return if $key =~ /^~~~~/; |
108
|
4
|
50
|
|
|
|
48
|
return( (delete $cache->{$key}) ? 1 : 0 ); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub clear |
112
|
|
|
|
|
|
|
{ |
113
|
2
|
|
|
2
|
1
|
36
|
my $cache = shift; |
114
|
2
|
|
|
|
|
13
|
my @keys = grep { !/^~~~~/ } keys %$cache; |
|
8
|
|
|
|
|
53
|
|
115
|
2
|
|
|
|
|
36
|
delete $cache->{$_} for @keys; |
116
|
2
|
|
|
|
|
12
|
return scalar(@keys); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub purge |
120
|
|
|
|
|
|
|
{ |
121
|
1
|
|
|
1
|
1
|
3000172
|
my $cache = shift; |
122
|
1
|
|
|
|
|
3
|
my $now = time; |
123
|
1
|
|
|
|
|
4
|
my @keys = |
124
|
1
|
50
|
|
|
|
16
|
grep { my $e = $cache->{$_}[1]; $e >= 0 && $e < $now } |
|
3
|
|
|
|
|
21
|
|
125
|
1
|
|
|
|
|
8
|
grep { !/^~~~~/ } keys %$cache; |
126
|
1
|
|
|
|
|
6
|
delete $cache->{$_} for @keys; |
127
|
1
|
|
|
|
|
5
|
return scalar(@keys); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub get_keys |
131
|
|
|
|
|
|
|
{ |
132
|
7
|
|
|
7
|
1
|
24
|
my $cache = shift; |
133
|
7
|
|
|
|
|
27
|
my @keys = grep { !/^~~~~/ } keys %$cache; |
|
22
|
|
|
|
|
89
|
|
134
|
7
|
|
|
|
|
289
|
return @keys; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub size |
138
|
|
|
|
|
|
|
{ |
139
|
6
|
|
|
6
|
1
|
70
|
scalar( my @keys = shift->get_keys ); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub AUTOLOAD |
143
|
|
|
|
|
|
|
{ |
144
|
8
|
|
|
8
|
|
207
|
return; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
__PACKAGE__ |
148
|
|
|
|
|
|
|
__END__ |