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.59'; |
7
|
32
|
|
|
32
|
|
209
|
use strict; |
|
32
|
|
|
|
|
59
|
|
|
32
|
|
|
|
|
873
|
|
8
|
32
|
|
|
32
|
|
167
|
use warnings; |
|
32
|
|
|
|
|
58
|
|
|
32
|
|
|
|
|
13898
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Override to handle busy_lock and expire_if. |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
sub get |
14
|
|
|
|
|
|
|
{ |
15
|
66
|
|
|
66
|
1
|
173
|
my ($self, $key, %params) = @_; |
16
|
66
|
50
|
|
|
|
167
|
die "must specify key" unless defined($key); |
17
|
|
|
|
|
|
|
|
18
|
66
|
|
|
|
|
252
|
foreach my $param (keys(%params)) { |
19
|
10
|
50
|
|
|
|
88
|
unless ($param =~ /^(busy_lock|expire_if)$/) { |
20
|
0
|
|
|
|
|
0
|
die "unknown param '$param'"; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
66
|
|
|
|
|
272
|
$self->_conditionally_auto_purge_on_get(); |
25
|
|
|
|
|
|
|
|
26
|
66
|
100
|
|
|
|
660
|
if (my $sub = $params{expire_if}) { |
27
|
6
|
|
|
|
|
37
|
$self->expire_if($key, $sub); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
66
|
100
|
|
|
|
240
|
my $object = $self->get_object($key) or |
31
|
|
|
|
|
|
|
return undef; |
32
|
|
|
|
|
|
|
|
33
|
45
|
100
|
|
|
|
28514
|
if (Cache::BaseCache::Object_Has_Expired($object)) |
34
|
|
|
|
|
|
|
{ |
35
|
13
|
100
|
|
|
|
469
|
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
|
|
|
|
|
23
|
my $busy_lock_time = Cache::BaseCache::Canonicalize_Expiration_Time($params{busy_lock}); |
40
|
4
|
|
|
|
|
200
|
$object->set_expires_at(time + $busy_lock_time); |
41
|
4
|
|
|
|
|
37
|
$self->set_object($key, $object); |
42
|
|
|
|
|
|
|
} else { |
43
|
9
|
|
|
|
|
54
|
$self->remove($key); |
44
|
|
|
|
|
|
|
} |
45
|
13
|
|
|
|
|
12449
|
return undef; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
32
|
|
|
|
|
819
|
return $object->get_data( ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub expire |
52
|
|
|
|
|
|
|
{ |
53
|
5
|
|
|
5
|
1
|
16
|
my ($self, $key) = @_; |
54
|
|
|
|
|
|
|
|
55
|
5
|
50
|
|
|
|
16
|
if (my $obj = $self->get_object($key)) { |
56
|
5
|
|
|
|
|
2705
|
$obj->set_expires_at(time-1); |
57
|
5
|
|
|
|
|
34
|
$self->set_object($key, $obj); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub expire_if |
62
|
|
|
|
|
|
|
{ |
63
|
6
|
|
|
6
|
1
|
16
|
my ($self, $key, $sub) = @_; |
64
|
6
|
50
|
33
|
|
|
37
|
die "must specify subroutine" unless defined($sub) and ref($sub) eq 'CODE'; |
65
|
|
|
|
|
|
|
|
66
|
6
|
100
|
|
|
|
19
|
if (my $obj = $self->get_object($key)) { |
67
|
5
|
|
|
|
|
2847
|
my $retval = $sub->($obj); |
68
|
5
|
100
|
|
|
|
25
|
if ($retval) { |
69
|
2
|
|
|
|
|
17
|
$self->expire($key); |
70
|
|
|
|
|
|
|
} |
71
|
5
|
|
|
|
|
1888
|
return $retval; |
72
|
|
|
|
|
|
|
} else { |
73
|
1
|
|
|
|
|
174
|
return 1; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |