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