line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package POE::Component::Cache; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2988
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
47
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
5
|
1
|
|
|
1
|
|
1417
|
use bytes; |
|
1
|
|
|
|
|
17
|
|
|
1
|
|
|
|
|
5
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
2356
|
use POE; |
|
1
|
|
|
|
|
73830
|
|
|
1
|
|
|
|
|
6
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.1.1'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new() |
12
|
|
|
|
|
|
|
{ |
13
|
0
|
|
|
0
|
0
|
|
my ($class) = shift; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
my $name = $class . '->new()'; |
16
|
|
|
|
|
|
|
|
17
|
0
|
0
|
|
|
|
|
die "$name requires an even number of arguments" unless (@_ & 1); |
18
|
0
|
|
|
|
|
|
my %params = @_; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my $life = delete $params{LifeTime}; |
21
|
|
|
|
|
|
|
|
22
|
0
|
0
|
|
|
|
|
if($life =~ /m$/) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
23
|
|
|
|
|
|
|
{ |
24
|
0
|
|
|
|
|
|
$life =~ s/m//; |
25
|
0
|
|
|
|
|
|
$life *= 60; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
} elsif ($life =~ /s$/) { |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
$life =~ s/s//; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
} elsif ($life =~ /^\d+$/) { |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
} else { |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
die "The $name LifeTime parameter must be a". |
36
|
|
|
|
|
|
|
" number or a number ending in 's' or 'm'"; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $alias = delete $params{Alias}; |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
$alias = defined($alias) ? $alias : 'POCO::CACHE'; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
POE::Session->create( |
44
|
|
|
|
|
|
|
inline_states => { |
45
|
|
|
|
|
|
|
_start => \&start, |
46
|
|
|
|
|
|
|
_stop => \&stop, |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
store => \&store, |
49
|
|
|
|
|
|
|
retrieve => \&retrieve, |
50
|
|
|
|
|
|
|
status => \&status, |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
adjust_life => \&adjust_life, |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
_cache_death => \&cache_death |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
}, |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
heap => { |
59
|
|
|
|
|
|
|
CONFIG => { |
60
|
|
|
|
|
|
|
life => $life, |
61
|
|
|
|
|
|
|
alias => $alias |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
}, |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return undef; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub start() |
71
|
|
|
|
|
|
|
{ |
72
|
0
|
|
|
0
|
0
|
|
my ($kernel, $heap) = @_[KERNEL, HEAP]; |
73
|
0
|
|
|
|
|
|
$kernel->alias_set($heap->{'CONFIG'}->{'alias'}); |
74
|
0
|
|
|
|
|
|
$heap->{'CACHE_TABLE'} = {}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub stop() |
78
|
|
|
|
|
|
|
{ |
79
|
0
|
|
|
0
|
0
|
|
my ($kernel, $heap) = @_[KERNEL, HEAP]; |
80
|
0
|
|
|
|
|
|
$kernel->alias_remove(); |
81
|
0
|
|
|
|
|
|
delete $heap->{'CACHE_TABLE'}; |
82
|
0
|
|
|
|
|
|
$kernel->alarm_remove_all(); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub store() |
86
|
|
|
|
|
|
|
{ |
87
|
0
|
|
|
0
|
0
|
|
my ($kernel, $heap, $key, $ref) = @_[KERNEL, HEAP, ARG0, ARG1]; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
$heap->{'CACHE_TABLE'}->{$key} = $ref; |
90
|
0
|
|
|
|
|
|
$kernel->delay_set('_cache_death', $heap->{'CONFIG'}->{'life'}, $key); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub retrieve() |
95
|
|
|
|
|
|
|
{ |
96
|
0
|
|
|
0
|
0
|
|
my ($heap, $key) = @_[HEAP, ARG0]; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return $heap->{'CACHE_TABLE'}->{$key}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub status() |
102
|
|
|
|
|
|
|
{ |
103
|
0
|
|
|
0
|
0
|
|
my ($heap, $key) = @_[HEAP, ARG0]; |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
if(exists($heap->{'CACHE_TABLE'}->{$key})) |
106
|
|
|
|
|
|
|
{ |
107
|
0
|
|
|
|
|
|
return 1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
} else { |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
return 0; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub adjust_life() |
116
|
|
|
|
|
|
|
{ |
117
|
0
|
|
|
0
|
0
|
|
my ($heap, $life) = @_[HEAP, ARG0]; |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
$heap->{'CONFIG'}->{'life'} = $life; |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
return; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub cache_death() |
125
|
|
|
|
|
|
|
{ |
126
|
0
|
|
|
0
|
0
|
|
my ($heap, $key) = @_[HEAP, ARG0]; |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
delete $heap->{'CACHE_TABLE'}->{$key}; |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
return; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; |