line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cache::LRU::WithExpires; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
50452
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
83
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
48
|
|
5
|
2
|
|
|
2
|
|
39
|
use 5.008_001; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
114
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1910
|
use parent 'Cache::LRU'; |
|
2
|
|
|
|
|
919
|
|
|
2
|
|
|
|
|
11
|
|
9
|
2
|
|
|
2
|
|
101054
|
use Time::HiRes (); |
|
2
|
|
|
|
|
3917
|
|
|
2
|
|
|
|
|
80
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
14
|
use constant NO_EXPIRES => 0; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
622
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub set { |
14
|
5
|
|
|
5
|
1
|
13279
|
my ($self, $key, $value, $expires) = @_; |
15
|
5
|
100
|
|
|
|
28
|
$expires = $expires ? Time::HiRes::time() + $expires : NO_EXPIRES; |
16
|
5
|
|
|
|
|
17
|
$value = [$value, $expires]; |
17
|
5
|
|
|
|
|
31
|
$self->SUPER::set($key, $value); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub get { |
21
|
5
|
|
|
5
|
1
|
402108
|
my ($self, $key) = @_; |
22
|
5
|
|
|
|
|
191
|
my $value = $self->SUPER::get($key); |
23
|
5
|
50
|
|
|
|
144
|
return undef unless defined $value; ## no critic |
24
|
|
|
|
|
|
|
|
25
|
5
|
|
|
|
|
22
|
($value, my $expires) = @$value; |
26
|
5
|
100
|
|
|
|
522
|
return $value if $expires == NO_EXPIRES; |
27
|
3
|
100
|
|
|
|
26
|
if ($expires - Time::HiRes::time() < 0) { |
28
|
2
|
|
|
|
|
28
|
$self->remove($key); |
29
|
2
|
|
|
|
|
43
|
return undef; ## no critic |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
6
|
return $value; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
1; |
36
|
|
|
|
|
|
|
__END__ |