line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cache::Moustache; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
32524
|
use 5.005; |
|
2
|
|
|
|
|
11
|
|
4
|
|
|
|
|
|
|
my $cpants = q/ |
5
|
|
|
|
|
|
|
use strict; |
6
|
|
|
|
|
|
|
use warnings; |
7
|
|
|
|
|
|
|
/; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
BEGIN { |
10
|
2
|
|
|
2
|
|
9
|
$Cache::Moustache::AUTHORITY = 'cpan:TOBYINK'; |
11
|
2
|
|
|
|
|
2176
|
$Cache::Moustache::VERSION = '0.006'; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub isa |
15
|
|
|
|
|
|
|
{ |
16
|
2
|
|
|
2
|
1
|
7
|
my $what = $_[1]; |
17
|
|
|
|
|
|
|
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
|
2
|
50
|
|
|
|
48
|
}->{$what}; |
26
|
0
|
|
|
|
|
0
|
return !!0; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new |
30
|
|
|
|
|
|
|
{ |
31
|
3
|
|
|
3
|
1
|
175
|
my ($class, %args) = @_; |
32
|
3
|
100
|
66
|
|
|
28
|
return $class if ref $class && $class->isa(__PACKAGE__); |
33
|
1
|
|
|
|
|
7
|
my %self = map { ;"~~~~$_" => $args{$_} } keys %args; |
|
1
|
|
|
|
|
12
|
|
34
|
1
|
|
50
|
|
|
12
|
$self{'~~~~default_expires_in'} ||= 3600; |
35
|
1
|
|
|
|
|
9
|
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
|
|
1114
|
require Storable; |
67
|
3
|
|
|
|
|
4098
|
shift; |
68
|
3
|
|
|
|
|
159
|
goto \&Storable::dclone; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub set |
72
|
|
|
|
|
|
|
{ |
73
|
18
|
|
|
18
|
1
|
3000564
|
my ($cache, $key, $data, $expires_in) = @_; |
74
|
18
|
50
|
|
|
|
83
|
return if $key =~ /^~~~~/; |
75
|
|
|
|
|
|
|
|
76
|
18
|
50
|
66
|
|
|
74
|
$data = $cache->_clone($data) if ref $data && $cache->{'~~~~clone_references'}; |
77
|
|
|
|
|
|
|
|
78
|
18
|
100
|
|
|
|
71
|
$expires_in = $cache->{'~~~~default_expires_in'} if !defined $expires_in; |
79
|
|
|
|
|
|
|
|
80
|
18
|
50
|
|
|
|
124
|
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
|
|
|
|
67
|
my $expires_at = ($expires_in < 0) ? $expires_in : (time + $expires_in); |
88
|
18
|
|
|
|
|
98
|
$cache->{$key} = [$data, $expires_at]; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub get |
92
|
|
|
|
|
|
|
{ |
93
|
14
|
|
|
14
|
1
|
6006664
|
my ($cache, $key) = @_; |
94
|
14
|
50
|
|
|
|
53
|
return if $key =~ /^~~~~/; |
95
|
14
|
100
|
|
|
|
57
|
return unless exists $cache->{$key}; |
96
|
|
|
|
|
|
|
|
97
|
11
|
|
|
|
|
24
|
my $expires_at = $cache->{$key}[1]; |
98
|
11
|
100
|
66
|
|
|
78
|
if ($expires_at >= 0 and $expires_at < time) |
99
|
|
|
|
|
|
|
{ |
100
|
2
|
|
|
|
|
25
|
$cache->remove($key); |
101
|
2
|
|
|
|
|
18
|
return; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
9
|
|
|
|
|
36
|
$cache->{$key}[0]; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub remove |
108
|
|
|
|
|
|
|
{ |
109
|
4
|
|
|
4
|
1
|
90
|
my ($cache, $key) = @_; |
110
|
|
|
|
|
|
|
|
111
|
4
|
50
|
|
|
|
20
|
if (ref $key eq 'Regexp') { |
112
|
0
|
0
|
|
|
|
0
|
my @keys = grep { $_ =~ $key and not !/^~~~~/ } keys %$cache; |
|
0
|
|
|
|
|
0
|
|
113
|
0
|
|
|
|
|
0
|
delete @{$cache}{@keys}; |
|
0
|
|
|
|
|
0
|
|
114
|
0
|
|
|
|
|
0
|
return scalar(@keys); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
4
|
50
|
|
|
|
17
|
return 0 if $key =~ /^~~~~/; |
118
|
4
|
50
|
|
|
|
32
|
return( (delete $cache->{$key}) ? 1 : 0 ); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub clear |
122
|
|
|
|
|
|
|
{ |
123
|
2
|
|
|
2
|
1
|
34
|
my $cache = shift; |
124
|
2
|
|
|
|
|
20
|
my @keys = grep !/^~~~~/, keys %$cache; |
125
|
2
|
|
|
|
|
23
|
delete $cache->{$_} for @keys; |
126
|
2
|
|
|
|
|
8
|
return scalar(@keys); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub purge |
130
|
|
|
|
|
|
|
{ |
131
|
1
|
|
|
1
|
1
|
3000159
|
my $cache = shift; |
132
|
1
|
|
|
|
|
7
|
my $now = time; |
133
|
|
|
|
|
|
|
my @keys = |
134
|
1
|
50
|
|
|
|
20
|
grep { my $e = $cache->{$_}[1]; $e >= 0 && $e < $now } |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
19
|
|
135
|
|
|
|
|
|
|
grep !/^~~~~/, keys %$cache; |
136
|
1
|
|
|
|
|
6
|
delete @{$cache}{@keys}; |
|
1
|
|
|
|
|
6
|
|
137
|
1
|
|
|
|
|
6
|
return scalar(@keys); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub get_keys |
141
|
|
|
|
|
|
|
{ |
142
|
7
|
|
|
7
|
1
|
20
|
my $cache = shift; |
143
|
7
|
|
|
|
|
57
|
my @keys = grep !/^~~~~/, keys %$cache; |
144
|
7
|
|
|
|
|
37
|
return @keys; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub size |
148
|
|
|
|
|
|
|
{ |
149
|
6
|
|
|
6
|
1
|
63
|
scalar( my @keys = shift->get_keys ); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub AUTOLOAD |
153
|
|
|
|
|
|
|
{ |
154
|
8
|
|
|
8
|
|
279
|
return; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
__PACKAGE__ |
158
|
|
|
|
|
|
|
__END__ |