/usr/share/perl5/Cache/CacheMetaData.pm is in libcache-cache-perl 1.08-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | ######################################################################
# $Id: CacheMetaData.pm,v 1.12 2002/04/07 17:04:46 dclinton Exp $
# Copyright (C) 2001-2003 DeWitt Clinton All Rights Reserved
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed or
# implied. See the License for the specific language governing
# rights and limitations under the License.
######################################################################
package Cache::CacheMetaData;
use strict;
use Cache::Cache qw( $EXPIRES_NOW $EXPIRES_NEVER );
#
# the cache meta data structure looks something like the following:
#
# %meta_data_hash =
# (
# $key_1 => [ $expires_at, $accessed_at, $object_size ],
# $key_2 => [ $expires_at, $accessed_at, $object_size ],
# ...
# )
#
my $_EXPIRES_AT_OFFSET = 0;
my $_ACCESS_AT_OFFSET = 1;
my $_SIZE_OFFSET = 2;
sub new
{
my ( $proto ) = @_;
my $class = ref( $proto ) || $proto;
my $self = {};
bless( $self, $class );
$self->_set_meta_data_hash_ref( { } );
$self->_set_cache_size( 0 );
return $self;
}
sub insert
{
my ( $self, $p_object ) = @_;
$self->_insert_object_expires_at( $p_object );
$self->_insert_object_accessed_at( $p_object );
$self->_insert_object_size( $p_object );
$self->_set_cache_size( $self->get_cache_size( ) + $p_object->get_size( ) );
}
sub remove
{
my ( $self, $p_key ) = @_;
$self->_set_cache_size( $self->get_cache_size( ) -
$self->build_object_size( $p_key ) );
delete $self->_get_meta_data_hash_ref( )->{ $p_key };
}
sub build_removal_list
{
my ( $self ) = @_;
my $meta_data_hash_ref = $self->_get_meta_data_hash_ref( );
return
sort
{
my $a_expires_at = $meta_data_hash_ref->{ $a }->[ $_EXPIRES_AT_OFFSET ];
my $b_expires_at = $meta_data_hash_ref->{ $b }->[ $_EXPIRES_AT_OFFSET ];
my $a_accessed_at = $meta_data_hash_ref->{ $a }->[ $_ACCESS_AT_OFFSET ];
my $b_accessed_at = $meta_data_hash_ref->{ $b }->[ $_ACCESS_AT_OFFSET ];
if ( $a_expires_at eq $b_expires_at )
{
return ( $a_accessed_at <=> $b_accessed_at );
}
return -1 if $a_expires_at eq $EXPIRES_NOW;
return 1 if $b_expires_at eq $EXPIRES_NOW;
return 1 if $a_expires_at eq $EXPIRES_NEVER;
return -1 if $b_expires_at eq $EXPIRES_NEVER;
return ( $a_expires_at <=> $b_expires_at );
} keys %$meta_data_hash_ref;
}
sub build_object_size
{
my ( $self, $p_key ) = @_;
return $self->_get_meta_data_hash_ref( )->{ $p_key }->[ $_SIZE_OFFSET ];
}
sub _insert_object_meta_data
{
my ( $self, $p_object, $p_offset, $p_value ) = @_;
$self->_get_meta_data_hash_ref( )->{ $p_object->get_key( ) }->[ $p_offset ] =
$p_value;
}
sub _insert_object_expires_at
{
my ( $self, $p_object ) = @_;
$self->_insert_object_meta_data( $p_object,
$_EXPIRES_AT_OFFSET,
$p_object->get_expires_at( ) );
}
sub _insert_object_accessed_at
{
my ( $self, $p_object ) = @_;
$self->_insert_object_meta_data( $p_object,
$_ACCESS_AT_OFFSET,
$p_object->get_accessed_at( ) );
}
sub _insert_object_size
{
my ( $self, $p_object ) = @_;
$self->_insert_object_meta_data( $p_object,
$_SIZE_OFFSET,
$p_object->get_size( ) );
}
sub get_cache_size
{
my ( $self ) = @_;
return $self->{_Cache_Size};
}
sub _set_cache_size
{
my ( $self, $cache_size ) = @_;
$self->{_Cache_Size} = $cache_size;
}
sub _get_meta_data_hash_ref
{
my ( $self ) = @_;
return $self->{_Meta_Data_Hash_Ref};
}
sub _set_meta_data_hash_ref
{
my ( $self, $meta_data_hash_ref ) = @_;
$self->{_Meta_Data_Hash_Ref} = $meta_data_hash_ref;
}
1;
__END__
=pod
=head1 NAME
Cache::CacheMetaData -- data about objects in the cache
=head1 DESCRIPTION
The CacheMetaData object is used by size aware caches to keep track of
the state of the cache and efficiently return information such as an
objects size or an ordered list of identifiers to be removed when a
cache size is being limited. End users will not normally use
CacheMetaData directly.
=head1 SYNOPSIS
use Cache::CacheMetaData;
my $cache_meta_data = new Cache::CacheMetaData( );
foreach my $key ( $cache->get_keys( ) )
{
my $object = $cache->get_object( $key ) or
next;
$cache_meta_data->insert( $object );
}
my $current_size = $cache_meta_data->get_cache_size( );
my @removal_list = $cache_meta_data->build_removal_list( );
=head1 METHODS
=over
=item B<new( )>
Construct a new Cache::CacheMetaData object
=item B<insert( $object )>
Inform the CacheMetaData about the object I<$object> in the cache.
=item B<remove( $key )>
Inform the CacheMetaData that the object specified by I<$key> is no
longer in the cache.
=item B<build_removal_list( )>
Create a list of the keys in the cache, ordered as follows:
1) objects that expire now
2) objects expiring at a particular time, with ties broken by the time
at which they were least recently accessed
3) objects that never expire, sub ordered by the time at which they
were least recently accessed
NOTE: This could be improved further by taking the size into account
on accessed_at ties. However, this type of tie is unlikely in normal
usage.
=item B<build_object_size( $key )>
Return the size of an object specified by I<$key>.
=back
=head1 PROPERTIES
=over
=item B<get_cache_size>
The total size of the objects in the cache
=back
=head1 SEE ALSO
Cache::Cache, Cache::CacheSizer, Cache::SizeAwareCache
=head1 AUTHOR
Original author: DeWitt Clinton <dewitt@unto.net>
Last author: $Author: dclinton $
Copyright (C) 2001-2003 DeWitt Clinton
=cut
|