line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
###################################################################### |
2
|
|
|
|
|
|
|
# $Id: SizeAwareFileCache.pm,v 1.28 2002/04/07 17:04:46 dclinton Exp $ |
3
|
|
|
|
|
|
|
# Copyright (C) 2001-2003 DeWitt Clinton All Rights Reserved |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Software distributed under the License is distributed on an "AS |
6
|
|
|
|
|
|
|
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or |
7
|
|
|
|
|
|
|
# implied. See the License for the specific language governing |
8
|
|
|
|
|
|
|
# rights and limitations under the License. |
9
|
|
|
|
|
|
|
###################################################################### |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
package Cache::SizeAwareFileCache; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
587
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
16
|
1
|
|
|
1
|
|
7
|
use vars qw( @ISA ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
17
|
1
|
|
|
1
|
|
584
|
use Cache::CacheSizer; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
32
|
|
18
|
1
|
|
|
1
|
|
7
|
use Cache::CacheUtils qw( Static_Params ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
44
|
|
19
|
1
|
|
|
1
|
|
530
|
use Cache::FileCache; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
48
|
|
20
|
1
|
|
|
1
|
|
6
|
use Cache::SizeAwareCache qw( $NO_MAX_SIZE ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
732
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
@ISA = qw ( Cache::FileCache Cache::SizeAwareCache ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $DEFAULT_MAX_SIZE = $NO_MAX_SIZE; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub Clear |
30
|
|
|
|
|
|
|
{ |
31
|
8
|
|
|
8
|
1
|
43
|
my ( $p_optional_cache_root ) = Static_Params( @_ ); |
32
|
|
|
|
|
|
|
|
33
|
8
|
|
|
|
|
39
|
Cache::FileCache::Clear( $p_optional_cache_root ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub Purge |
38
|
|
|
|
|
|
|
{ |
39
|
2
|
|
|
2
|
1
|
88
|
my ( $p_optional_cache_root ) = Static_Params( @_ ); |
40
|
|
|
|
|
|
|
|
41
|
2
|
|
|
|
|
17
|
Cache::FileCache::Purge( $p_optional_cache_root ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub Size |
46
|
|
|
|
|
|
|
{ |
47
|
7
|
|
|
7
|
1
|
36
|
my ( $p_optional_cache_root ) = Static_Params( @_ ); |
48
|
|
|
|
|
|
|
|
49
|
7
|
|
|
|
|
30
|
return Cache::FileCache::Size( $p_optional_cache_root ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub new |
54
|
|
|
|
|
|
|
{ |
55
|
3
|
|
|
3
|
1
|
418
|
my ( $self ) = _new( @_ ); |
56
|
3
|
|
|
|
|
16
|
$self->_complete_initialization( ); |
57
|
3
|
|
|
|
|
13
|
return $self; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub get |
62
|
|
|
|
|
|
|
{ |
63
|
31
|
|
|
31
|
1
|
66
|
my ( $self, $p_key ) = @_; |
64
|
|
|
|
|
|
|
|
65
|
31
|
|
|
|
|
107
|
$self->_get_cache_sizer( )->update_access_time( $p_key ); |
66
|
31
|
|
|
|
|
374
|
return $self->SUPER::get( $p_key ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub limit_size |
71
|
|
|
|
|
|
|
{ |
72
|
2
|
|
|
2
|
1
|
5
|
my ( $self, $p_new_size ) = @_; |
73
|
|
|
|
|
|
|
|
74
|
2
|
|
|
|
|
10
|
$self->_get_cache_sizer( )->limit_size( $p_new_size ); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub set |
80
|
|
|
|
|
|
|
{ |
81
|
33
|
|
|
33
|
1
|
95
|
my ( $self, $p_key, $p_data, $p_expires_in ) = @_; |
82
|
|
|
|
|
|
|
|
83
|
33
|
|
|
|
|
280
|
$self->SUPER::set( $p_key, $p_data, $p_expires_in ); |
84
|
33
|
|
|
|
|
869
|
$self->_get_cache_sizer( )->limit_size( $self->get_max_size( ) ); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _new |
90
|
|
|
|
|
|
|
{ |
91
|
3
|
|
|
3
|
|
8
|
my ( $proto, $p_options_hash_ref ) = @_; |
92
|
3
|
|
66
|
|
|
18
|
my $class = ref( $proto ) || $proto; |
93
|
3
|
|
|
|
|
32
|
my $self = $class->SUPER::_new( $p_options_hash_ref ); |
94
|
3
|
|
|
|
|
12
|
$self->_initialize_cache_sizer( ); |
95
|
3
|
|
|
|
|
7
|
return $self; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _initialize_cache_sizer |
100
|
|
|
|
|
|
|
{ |
101
|
3
|
|
|
3
|
|
7
|
my ( $self ) = @_; |
102
|
|
|
|
|
|
|
|
103
|
3
|
|
|
|
|
9
|
my $max_size = $self->_read_option( 'max_size', $DEFAULT_MAX_SIZE ); |
104
|
3
|
|
|
|
|
80
|
$self->_set_cache_sizer( new Cache::CacheSizer( $self, $max_size ) ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub get_max_size |
109
|
|
|
|
|
|
|
{ |
110
|
33
|
|
|
33
|
0
|
72
|
my ( $self ) = @_; |
111
|
|
|
|
|
|
|
|
112
|
33
|
|
|
|
|
72
|
return $self->_get_cache_sizer( )->get_max_size( ); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub set_max_size |
117
|
|
|
|
|
|
|
{ |
118
|
1
|
|
|
1
|
0
|
3
|
my ( $self, $p_max_size ) = @_; |
119
|
|
|
|
|
|
|
|
120
|
1
|
|
|
|
|
3
|
$self->_get_cache_sizer( )->set_max_size( $p_max_size ); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub _get_cache_sizer |
125
|
|
|
|
|
|
|
{ |
126
|
100
|
|
|
100
|
|
192
|
my ( $self ) = @_; |
127
|
|
|
|
|
|
|
|
128
|
100
|
|
|
|
|
520
|
return $self->{_Cache_Sizer}; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub _set_cache_sizer |
133
|
|
|
|
|
|
|
{ |
134
|
3
|
|
|
3
|
|
7
|
my ( $self, $p_cache_sizer ) = @_; |
135
|
|
|
|
|
|
|
|
136
|
3
|
|
|
|
|
9
|
$self->{_Cache_Sizer} = $p_cache_sizer; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
__END__ |