line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (c) 1998-2005 by Jonathan Swartz. All rights reserved. |
2
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify it |
3
|
|
|
|
|
|
|
# under the same terms as Perl itself. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package HTML::Mason::Cache::BaseCache; |
6
|
|
|
|
|
|
|
$HTML::Mason::Cache::BaseCache::VERSION = '1.60'; |
7
|
32
|
|
|
32
|
|
212
|
use strict; |
|
32
|
|
|
|
|
59
|
|
|
32
|
|
|
|
|
861
|
|
8
|
32
|
|
|
32
|
|
184
|
use warnings; |
|
32
|
|
|
|
|
60
|
|
|
32
|
|
|
|
|
14050
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Override to handle busy_lock and expire_if. |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
sub get |
14
|
|
|
|
|
|
|
{ |
15
|
66
|
|
|
66
|
1
|
186
|
my ($self, $key, %params) = @_; |
16
|
66
|
50
|
|
|
|
169
|
die "must specify key" unless defined($key); |
17
|
|
|
|
|
|
|
|
18
|
66
|
|
|
|
|
216
|
foreach my $param (keys(%params)) { |
19
|
10
|
50
|
|
|
|
104
|
unless ($param =~ /^(busy_lock|expire_if)$/) { |
20
|
0
|
|
|
|
|
0
|
die "unknown param '$param'"; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
66
|
|
|
|
|
275
|
$self->_conditionally_auto_purge_on_get(); |
25
|
|
|
|
|
|
|
|
26
|
66
|
100
|
|
|
|
682
|
if (my $sub = $params{expire_if}) { |
27
|
6
|
|
|
|
|
36
|
$self->expire_if($key, $sub); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
66
|
100
|
|
|
|
228
|
my $object = $self->get_object($key) or |
31
|
|
|
|
|
|
|
return undef; |
32
|
|
|
|
|
|
|
|
33
|
45
|
100
|
|
|
|
29266
|
if (Cache::BaseCache::Object_Has_Expired($object)) |
34
|
|
|
|
|
|
|
{ |
35
|
13
|
100
|
|
|
|
497
|
if ($params{busy_lock}) { |
36
|
|
|
|
|
|
|
# If busy_lock value provided, set a new "temporary" |
37
|
|
|
|
|
|
|
# expiration time that many seconds forward, and return |
38
|
|
|
|
|
|
|
# undef so that this process will start recomputing. |
39
|
4
|
|
|
|
|
25
|
my $busy_lock_time = Cache::BaseCache::Canonicalize_Expiration_Time($params{busy_lock}); |
40
|
4
|
|
|
|
|
208
|
$object->set_expires_at(time + $busy_lock_time); |
41
|
4
|
|
|
|
|
45
|
$self->set_object($key, $object); |
42
|
|
|
|
|
|
|
} else { |
43
|
9
|
|
|
|
|
50
|
$self->remove($key); |
44
|
|
|
|
|
|
|
} |
45
|
13
|
|
|
|
|
30324
|
return undef; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
32
|
|
|
|
|
714
|
return $object->get_data( ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub expire |
52
|
|
|
|
|
|
|
{ |
53
|
5
|
|
|
5
|
1
|
23
|
my ($self, $key) = @_; |
54
|
|
|
|
|
|
|
|
55
|
5
|
50
|
|
|
|
21
|
if (my $obj = $self->get_object($key)) { |
56
|
5
|
|
|
|
|
2630
|
$obj->set_expires_at(time-1); |
57
|
5
|
|
|
|
|
36
|
$self->set_object($key, $obj); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub expire_if |
62
|
|
|
|
|
|
|
{ |
63
|
6
|
|
|
6
|
1
|
29
|
my ($self, $key, $sub) = @_; |
64
|
6
|
50
|
33
|
|
|
35
|
die "must specify subroutine" unless defined($sub) and ref($sub) eq 'CODE'; |
65
|
|
|
|
|
|
|
|
66
|
6
|
100
|
|
|
|
16
|
if (my $obj = $self->get_object($key)) { |
67
|
5
|
|
|
|
|
2711
|
my $retval = $sub->($obj); |
68
|
5
|
100
|
|
|
|
26
|
if ($retval) { |
69
|
2
|
|
|
|
|
27
|
$self->expire($key); |
70
|
|
|
|
|
|
|
} |
71
|
5
|
|
|
|
|
11058
|
return $retval; |
72
|
|
|
|
|
|
|
} else { |
73
|
1
|
|
|
|
|
154
|
return 1; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |