line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
###################################################################### |
2
|
|
|
|
|
|
|
# $Id: CacheMetaData.pm,v 1.12 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
|
|
|
|
|
|
|
package Cache::CacheMetaData; |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
60
|
|
14
|
2
|
|
|
2
|
|
9
|
use Cache::Cache qw( $EXPIRES_NOW $EXPIRES_NEVER ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1580
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# the cache meta data structure looks something like the following: |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
# %meta_data_hash = |
20
|
|
|
|
|
|
|
# ( |
21
|
|
|
|
|
|
|
# $key_1 => [ $expires_at, $accessed_at, $object_size ], |
22
|
|
|
|
|
|
|
# $key_2 => [ $expires_at, $accessed_at, $object_size ], |
23
|
|
|
|
|
|
|
# ... |
24
|
|
|
|
|
|
|
# ) |
25
|
|
|
|
|
|
|
# |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $_EXPIRES_AT_OFFSET = 0; |
28
|
|
|
|
|
|
|
my $_ACCESS_AT_OFFSET = 1; |
29
|
|
|
|
|
|
|
my $_SIZE_OFFSET = 2; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub new |
33
|
|
|
|
|
|
|
{ |
34
|
6
|
|
|
6
|
1
|
14
|
my ( $proto ) = @_; |
35
|
6
|
|
33
|
|
|
36
|
my $class = ref( $proto ) || $proto; |
36
|
6
|
|
|
|
|
14
|
my $self = {}; |
37
|
6
|
|
|
|
|
19
|
bless( $self, $class ); |
38
|
6
|
|
|
|
|
105
|
$self->_set_meta_data_hash_ref( { } ); |
39
|
6
|
|
|
|
|
23
|
$self->_set_cache_size( 0 ); |
40
|
6
|
|
|
|
|
21
|
return $self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub insert |
45
|
|
|
|
|
|
|
{ |
46
|
20
|
|
|
20
|
1
|
35
|
my ( $self, $p_object ) = @_; |
47
|
|
|
|
|
|
|
|
48
|
20
|
|
|
|
|
47
|
$self->_insert_object_expires_at( $p_object ); |
49
|
20
|
|
|
|
|
55
|
$self->_insert_object_accessed_at( $p_object ); |
50
|
20
|
|
|
|
|
54
|
$self->_insert_object_size( $p_object ); |
51
|
20
|
|
|
|
|
49
|
$self->_set_cache_size( $self->get_cache_size( ) + $p_object->get_size( ) ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub remove |
56
|
|
|
|
|
|
|
{ |
57
|
14
|
|
|
14
|
1
|
22
|
my ( $self, $p_key ) = @_; |
58
|
|
|
|
|
|
|
|
59
|
14
|
|
|
|
|
29
|
$self->_set_cache_size( $self->get_cache_size( ) - |
60
|
|
|
|
|
|
|
$self->build_object_size( $p_key ) ); |
61
|
|
|
|
|
|
|
|
62
|
14
|
|
|
|
|
94
|
delete $self->_get_meta_data_hash_ref( )->{ $p_key }; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub build_removal_list |
67
|
|
|
|
|
|
|
{ |
68
|
6
|
|
|
6
|
1
|
15
|
my ( $self ) = @_; |
69
|
|
|
|
|
|
|
|
70
|
6
|
|
|
|
|
16
|
my $meta_data_hash_ref = $self->_get_meta_data_hash_ref( ); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
return |
73
|
|
|
|
|
|
|
sort |
74
|
24
|
|
|
|
|
40
|
{ |
75
|
6
|
|
|
|
|
48
|
my $a_expires_at = $meta_data_hash_ref->{ $a }->[ $_EXPIRES_AT_OFFSET ]; |
76
|
24
|
|
|
|
|
30
|
my $b_expires_at = $meta_data_hash_ref->{ $b }->[ $_EXPIRES_AT_OFFSET ]; |
77
|
24
|
|
|
|
|
33
|
my $a_accessed_at = $meta_data_hash_ref->{ $a }->[ $_ACCESS_AT_OFFSET ]; |
78
|
24
|
|
|
|
|
33
|
my $b_accessed_at = $meta_data_hash_ref->{ $b }->[ $_ACCESS_AT_OFFSET ]; |
79
|
|
|
|
|
|
|
|
80
|
24
|
100
|
|
|
|
51
|
if ( $a_expires_at eq $b_expires_at ) |
81
|
|
|
|
|
|
|
{ |
82
|
2
|
|
|
|
|
14
|
return ( $a_accessed_at <=> $b_accessed_at ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
22
|
50
|
|
|
|
46
|
return -1 if $a_expires_at eq $EXPIRES_NOW; |
86
|
22
|
50
|
|
|
|
50
|
return 1 if $b_expires_at eq $EXPIRES_NOW; |
87
|
22
|
50
|
|
|
|
39
|
return 1 if $a_expires_at eq $EXPIRES_NEVER; |
88
|
22
|
50
|
|
|
|
39
|
return -1 if $b_expires_at eq $EXPIRES_NEVER; |
89
|
|
|
|
|
|
|
|
90
|
22
|
|
|
|
|
48
|
return ( $a_expires_at <=> $b_expires_at ); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
} keys %$meta_data_hash_ref; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub build_object_size |
98
|
|
|
|
|
|
|
{ |
99
|
28
|
|
|
28
|
1
|
37
|
my ( $self, $p_key ) = @_; |
100
|
|
|
|
|
|
|
|
101
|
28
|
|
|
|
|
48
|
return $self->_get_meta_data_hash_ref( )->{ $p_key }->[ $_SIZE_OFFSET ]; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _insert_object_meta_data |
106
|
|
|
|
|
|
|
{ |
107
|
60
|
|
|
60
|
|
90
|
my ( $self, $p_object, $p_offset, $p_value ) = @_; |
108
|
|
|
|
|
|
|
|
109
|
60
|
|
|
|
|
109
|
$self->_get_meta_data_hash_ref( )->{ $p_object->get_key( ) }->[ $p_offset ] = |
110
|
|
|
|
|
|
|
$p_value; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _insert_object_expires_at |
115
|
|
|
|
|
|
|
{ |
116
|
20
|
|
|
20
|
|
28
|
my ( $self, $p_object ) = @_; |
117
|
|
|
|
|
|
|
|
118
|
20
|
|
|
|
|
56
|
$self->_insert_object_meta_data( $p_object, |
119
|
|
|
|
|
|
|
$_EXPIRES_AT_OFFSET, |
120
|
|
|
|
|
|
|
$p_object->get_expires_at( ) ); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub _insert_object_accessed_at |
125
|
|
|
|
|
|
|
{ |
126
|
20
|
|
|
20
|
|
31
|
my ( $self, $p_object ) = @_; |
127
|
|
|
|
|
|
|
|
128
|
20
|
|
|
|
|
64
|
$self->_insert_object_meta_data( $p_object, |
129
|
|
|
|
|
|
|
$_ACCESS_AT_OFFSET, |
130
|
|
|
|
|
|
|
$p_object->get_accessed_at( ) ); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub _insert_object_size |
135
|
|
|
|
|
|
|
{ |
136
|
20
|
|
|
20
|
|
30
|
my ( $self, $p_object ) = @_; |
137
|
|
|
|
|
|
|
|
138
|
20
|
|
|
|
|
59
|
$self->_insert_object_meta_data( $p_object, |
139
|
|
|
|
|
|
|
$_SIZE_OFFSET, |
140
|
|
|
|
|
|
|
$p_object->get_size( ) ); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub get_cache_size |
145
|
|
|
|
|
|
|
{ |
146
|
40
|
|
|
40
|
1
|
52
|
my ( $self ) = @_; |
147
|
|
|
|
|
|
|
|
148
|
40
|
|
|
|
|
107
|
return $self->{_Cache_Size}; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub _set_cache_size |
153
|
|
|
|
|
|
|
{ |
154
|
40
|
|
|
40
|
|
55
|
my ( $self, $cache_size ) = @_; |
155
|
|
|
|
|
|
|
|
156
|
40
|
|
|
|
|
142
|
$self->{_Cache_Size} = $cache_size; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub _get_meta_data_hash_ref |
161
|
|
|
|
|
|
|
{ |
162
|
108
|
|
|
108
|
|
122
|
my ( $self ) = @_; |
163
|
|
|
|
|
|
|
|
164
|
108
|
|
|
|
|
383
|
return $self->{_Meta_Data_Hash_Ref}; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub _set_meta_data_hash_ref |
169
|
|
|
|
|
|
|
{ |
170
|
6
|
|
|
6
|
|
13
|
my ( $self, $meta_data_hash_ref ) = @_; |
171
|
|
|
|
|
|
|
|
172
|
6
|
|
|
|
|
31
|
$self->{_Meta_Data_Hash_Ref} = $meta_data_hash_ref; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
1; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
__END__ |