CacheMetaData.pm

filter: Statementstmt 100% 57 / 57 Branchbran 60.0% 6 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 15 / 15 Podpod 100% 6 / 6 totaltotal 91.4% 85 / 93 SCAR 19.5
CC
7
Cov
91%
build_removal_list
6.2
new
2.0
BEGIN
1.0
CRAP 7.0
« CacheUtils.pm ↑ Summary MemoryCache.pm »
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Cache::Cache qw( $EXPIRES_NOW $EXPIRES_NEVER );
Subroutine BEGIN: called CC=1 SCAR=0.0
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 2 my $_EXPIRES_AT_OFFSET = 0;
28 2 my $_ACCESS_AT_OFFSET = 1;
29 2 my $_SIZE_OFFSET = 2;
30  
31  
32 sub new
33 {
34 6 ▶ my ( $proto ) = @_;
Subroutine new: called CC=2 SCAR=7.1
Pod documented
35 6 ▶ my $class = ref( $proto ) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
060
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
36 6 my $self = {};
37 6 bless( $self, $class );
38 6 $self->_set_meta_data_hash_ref( { } );
39 6 $self->_set_cache_size( 0 );
40 6 return $self;
41 }
42  
43  
44 sub insert
45 {
46 20 ▶ my ( $self, $p_object ) = @_;
Subroutine insert: called CC=1 SCAR=0.0
Pod documented
47  
48 20 $self->_insert_object_expires_at( $p_object );
49 20 $self->_insert_object_accessed_at( $p_object );
50 20 $self->_insert_object_size( $p_object );
51 20 $self->_set_cache_size( $self->get_cache_size( ) + $p_object->get_size( ) );
52 }
53  
54  
55 sub remove
56 {
57 14 ▶ my ( $self, $p_key ) = @_;
Subroutine remove: called CC=1 SCAR=0.0
Pod documented
58  
59 14 $self->_set_cache_size( $self->get_cache_size( ) -
60 $self->build_object_size( $p_key ) );
61  
62 14 delete $self->_get_meta_data_hash_ref( )->{ $p_key };
63 }
64  
65  
66 sub build_removal_list
67 {
68 6 ▶ my ( $self ) = @_;
Subroutine build_removal_list: called CC=6 SCAR=18.2
Pod documented
69  
70 6 my $meta_data_hash_ref = $self->_get_meta_data_hash_ref( );
71  
72 return
73 sort
74 {
75 6 my $a_expires_at = $meta_data_hash_ref->{ $a }->[ $_EXPIRES_AT_OFFSET ];
76 24 my $b_expires_at = $meta_data_hash_ref->{ $b }->[ $_EXPIRES_AT_OFFSET ];
77 24 my $a_accessed_at = $meta_data_hash_ref->{ $a }->[ $_ACCESS_AT_OFFSET ];
78 24 my $b_accessed_at = $meta_data_hash_ref->{ $b }->[ $_ACCESS_AT_OFFSET ];
79  
80 24 ▶ if ( $a_expires_at eq $b_expires_at )
Branch: 1 branch
BranchTrueFalseTotal
if ($a_expires_at eq $b_expires_at) 2 22 24
81 {
82 2 return ( $a_accessed_at <=> $b_accessed_at );
83 }
84  
85 22 ▶ return -1 if $a_expires_at eq $EXPIRES_NOW;
Branch: 1 branch
BranchTrueFalseTotal
if $a_expires_at eq $Cache::CacheMetaData::EXPIRES_NOW 0 22 22
86 22 ▶ return 1 if $b_expires_at eq $EXPIRES_NOW;
Branch: 1 branch
BranchTrueFalseTotal
if $b_expires_at eq $Cache::CacheMetaData::EXPIRES_NOW 0 22 22
87 22 ▶ return 1 if $a_expires_at eq $EXPIRES_NEVER;
Branch: 1 branch
BranchTrueFalseTotal
if $a_expires_at eq $Cache::CacheMetaData::EXPIRES_NEVER 0 22 22
88 22 ▶ return -1 if $b_expires_at eq $EXPIRES_NEVER;
Branch: 1 branch
BranchTrueFalseTotal
if $b_expires_at eq $Cache::CacheMetaData::EXPIRES_NEVER 0 22 22
89  
90 22 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 ▶ my ( $self, $p_key ) = @_;
Subroutine build_object_size: called CC=1 SCAR=0.0
Pod documented
100  
101 28 return $self->_get_meta_data_hash_ref( )->{ $p_key }->[ $_SIZE_OFFSET ];
102 }
103  
104  
105 sub _insert_object_meta_data
106 {
107 60 ▶ my ( $self, $p_object, $p_offset, $p_value ) = @_;
Subroutine _insert_object_meta_data: called CC=1 SCAR=0.0
108  
109 60 $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 ▶ my ( $self, $p_object ) = @_;
Subroutine _insert_object_expires_at: called CC=1 SCAR=0.0
117  
118 20 $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 ▶ my ( $self, $p_object ) = @_;
Subroutine _insert_object_accessed_at: called CC=1 SCAR=0.0
127  
128 20 $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 ▶ my ( $self, $p_object ) = @_;
Subroutine _insert_object_size: called CC=1 SCAR=0.0
137  
138 20 $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 ▶ my ( $self ) = @_;
Subroutine get_cache_size: called CC=1 SCAR=0.0
Pod documented
147  
148 40 return $self->{_Cache_Size};
149 }
150  
151  
152 sub _set_cache_size
153 {
154 40 ▶ my ( $self, $cache_size ) = @_;
Subroutine _set_cache_size: called CC=1 SCAR=0.0
155  
156 40 $self->{_Cache_Size} = $cache_size;
157 }
158  
159  
160 sub _get_meta_data_hash_ref
161 {
162 108 ▶ my ( $self ) = @_;
Subroutine _get_meta_data_hash_ref: called CC=1 SCAR=0.0
163  
164 108 return $self->{_Meta_Data_Hash_Ref};
165 }
166  
167  
168 sub _set_meta_data_hash_ref
169 {
170 6 ▶ my ( $self, $meta_data_hash_ref ) = @_;
Subroutine _set_meta_data_hash_ref: called CC=1 SCAR=0.0
171  
172 6 $self->{_Meta_Data_Hash_Ref} = $meta_data_hash_ref;
173 }
174  
175  
176 2 1;
177  
178  
179 __END__
« CacheUtils.pm ↑ Summary MemoryCache.pm »