line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pinwheel::Cache; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
27849
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
573
|
use Pinwheel::Cache::Null; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
7
|
use Exporter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
430
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(cache cache_clear cache_get cache_remove cache_set); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# By default use the Null backend |
15
|
|
|
|
|
|
|
my $backend = new Pinwheel::Cache::Null; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub cache_clear |
20
|
|
|
|
|
|
|
{ |
21
|
4
|
|
|
4
|
1
|
18
|
return $backend->clear(); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub cache_get |
25
|
|
|
|
|
|
|
{ |
26
|
16
|
|
|
16
|
1
|
35
|
my ($key) = @_; |
27
|
16
|
|
|
|
|
61
|
return $backend->get($key); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub cache_remove |
31
|
|
|
|
|
|
|
{ |
32
|
3
|
|
|
3
|
1
|
7
|
my ($key, $time) = @_; |
33
|
3
|
|
|
|
|
12
|
return $backend->remove($key, $time); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub cache_set |
37
|
|
|
|
|
|
|
{ |
38
|
6
|
|
|
6
|
1
|
31
|
my ($key, $value, $expires) = @_; |
39
|
6
|
|
|
|
|
25
|
return $backend->set($key, $value, $expires); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub cache |
43
|
|
|
|
|
|
|
{ |
44
|
8
|
|
|
8
|
1
|
39
|
my $valuefn = pop @_; |
45
|
8
|
|
|
|
|
15
|
my ($key, $expires) = @_; |
46
|
8
|
|
|
|
|
11
|
my ($value); |
47
|
|
|
|
|
|
|
|
48
|
8
|
|
|
|
|
27
|
$value = $backend->get($key); |
49
|
8
|
100
|
|
|
|
28
|
if (!defined($value)) { |
50
|
6
|
|
|
|
|
15
|
$value = $valuefn->(); |
51
|
6
|
100
|
|
|
|
37
|
$expires = $expires->($value) if ref($expires) eq 'CODE'; |
52
|
6
|
|
|
|
|
23
|
$backend->set($key, $value, $expires); |
53
|
|
|
|
|
|
|
} |
54
|
8
|
|
|
|
|
32
|
return $value; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub set_backend |
58
|
|
|
|
|
|
|
{ |
59
|
4
|
|
|
4
|
1
|
563
|
my ($b) = @_; |
60
|
4
|
100
|
|
|
|
20
|
$b = new Pinwheel::Cache::Null unless defined($b); |
61
|
4
|
|
|
|
|
11
|
$backend = $b; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__DATA__ |