line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
###################################################################### |
2
|
|
|
|
|
|
|
# $Id: CacheTester.pm,v 1.20 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::CacheTester; |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
1633
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
69
|
|
14
|
2
|
|
|
2
|
|
1411
|
use Cache::BaseCacheTester; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
52
|
|
15
|
2
|
|
|
2
|
|
13
|
use Cache::Cache; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
107
|
|
16
|
2
|
|
|
2
|
|
2343
|
use Error qw( :try ); |
|
2
|
|
|
|
|
16444
|
|
|
2
|
|
|
|
|
15
|
|
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
|
410
|
use vars qw( @ISA $EXPIRES_DELAY ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
4379
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
@ISA = qw ( Cache::BaseCacheTester ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$EXPIRES_DELAY = 2; |
23
|
|
|
|
|
|
|
$Error::Debug = 1; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub test |
26
|
|
|
|
|
|
|
{ |
27
|
2
|
|
|
2
|
1
|
17
|
my ( $self, $cache ) = @_; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
try |
30
|
|
|
|
|
|
|
{ |
31
|
2
|
|
|
2
|
|
78
|
$cache->Clear( ); |
32
|
2
|
|
|
|
|
27
|
$self->_test_one( $cache ); |
33
|
2
|
|
|
|
|
11
|
$self->_test_two( $cache ); |
34
|
2
|
|
|
|
|
10
|
$self->_test_three( $cache ); |
35
|
2
|
|
|
|
|
9
|
$self->_test_four( $cache ); |
36
|
2
|
|
|
|
|
18
|
$self->_test_five( $cache ); |
37
|
2
|
|
|
|
|
13
|
$self->_test_six( $cache ); |
38
|
2
|
|
|
|
|
13
|
$self->_test_seven( $cache ); |
39
|
2
|
|
|
|
|
11
|
$self->_test_eight( $cache ); |
40
|
2
|
|
|
|
|
18
|
$self->_test_nine( $cache ); |
41
|
2
|
|
|
|
|
16
|
$self->_test_ten( $cache ); |
42
|
2
|
|
|
|
|
17
|
$self->_test_eleven( $cache ); |
43
|
2
|
|
|
|
|
15
|
$self->_test_twelve( $cache ); |
44
|
2
|
|
|
|
|
15
|
$self->_test_thirteen( $cache ); |
45
|
2
|
|
|
|
|
12
|
$self->_test_fourteen( $cache ); |
46
|
2
|
|
|
|
|
9
|
$self->_test_fifteen( $cache ); |
47
|
2
|
|
|
|
|
15
|
$self->_test_sixteen( $cache ); |
48
|
2
|
|
|
|
|
14
|
$self->_test_seventeen( $cache ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
catch Error with |
51
|
|
|
|
|
|
|
{ |
52
|
0
|
|
|
0
|
|
0
|
my $error = shift; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
print STDERR "\nError:\n"; |
55
|
0
|
|
|
|
|
0
|
print STDERR $error->stringify( ) . "\n"; |
56
|
0
|
|
|
|
|
0
|
print STDERR $error->stacktrace( ) . "\n"; |
57
|
0
|
|
|
|
|
0
|
print STDERR "\n"; |
58
|
|
|
|
|
|
|
} |
59
|
2
|
|
|
|
|
31
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Test the getting, setting, and removal of a scalar |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _test_one |
65
|
|
|
|
|
|
|
{ |
66
|
2
|
|
|
2
|
|
5
|
my ( $self, $cache ) = @_; |
67
|
|
|
|
|
|
|
|
68
|
2
|
50
|
|
|
|
9
|
$cache or |
69
|
|
|
|
|
|
|
croak( "cache required" ); |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
5
|
my $key = 'Test Key'; |
72
|
|
|
|
|
|
|
|
73
|
2
|
|
|
|
|
3
|
my $value = 'Test Value'; |
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
17
|
$cache->set( $key, $value ); |
76
|
|
|
|
|
|
|
|
77
|
2
|
|
|
|
|
17
|
my $fetched_value = $cache->get( $key ); |
78
|
|
|
|
|
|
|
|
79
|
2
|
50
|
|
|
|
20
|
( $fetched_value eq $value ) ? |
80
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$fetched_value eq $value' ); |
81
|
|
|
|
|
|
|
|
82
|
2
|
|
|
|
|
71
|
$cache->remove( $key ); |
83
|
|
|
|
|
|
|
|
84
|
2
|
|
|
|
|
10
|
my $fetched_removed_value = $cache->get( $key ); |
85
|
|
|
|
|
|
|
|
86
|
2
|
50
|
|
|
|
15
|
( not defined $fetched_removed_value ) ? |
87
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( 'not defined $fetched_removed_value' ); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# Test the getting, setting, and removal of a list |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _test_two |
94
|
|
|
|
|
|
|
{ |
95
|
2
|
|
|
2
|
|
4
|
my ( $self, $cache ) = @_; |
96
|
|
|
|
|
|
|
|
97
|
2
|
50
|
|
|
|
11
|
$cache or |
98
|
|
|
|
|
|
|
croak( "cache required" ); |
99
|
|
|
|
|
|
|
|
100
|
2
|
|
|
|
|
5
|
my $key = 'Test Key'; |
101
|
|
|
|
|
|
|
|
102
|
2
|
|
|
|
|
6
|
my @value_list = ( 'One', 'Two', 'Three' ); |
103
|
|
|
|
|
|
|
|
104
|
2
|
|
|
|
|
10
|
$cache->set( $key, \@value_list ); |
105
|
|
|
|
|
|
|
|
106
|
2
|
|
|
|
|
8
|
my $fetched_value_list_ref = $cache->get( $key ); |
107
|
|
|
|
|
|
|
|
108
|
2
|
50
|
33
|
|
|
27
|
if ( ( $fetched_value_list_ref->[0] eq 'One' ) and |
|
|
|
33
|
|
|
|
|
109
|
|
|
|
|
|
|
( $fetched_value_list_ref->[1] eq 'Two' ) and |
110
|
|
|
|
|
|
|
( $fetched_value_list_ref->[2] eq 'Three' ) ) |
111
|
|
|
|
|
|
|
{ |
112
|
2
|
|
|
|
|
7
|
$self->ok( ); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
else |
115
|
|
|
|
|
|
|
{ |
116
|
0
|
|
|
|
|
0
|
$self->not_ok( 'fetched list does not match set list' ); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
2
|
|
|
|
|
10
|
$cache->remove( $key ); |
120
|
|
|
|
|
|
|
|
121
|
2
|
|
|
|
|
8
|
my $fetched_removed_value = $cache->get( $key ); |
122
|
|
|
|
|
|
|
|
123
|
2
|
50
|
|
|
|
13
|
( not defined $fetched_removed_value ) ? |
124
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( 'not defined $fetched_removed_value' ); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# Test the getting, setting, and removal of a blessed object |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub _test_three |
131
|
|
|
|
|
|
|
{ |
132
|
2
|
|
|
2
|
|
4
|
my ( $self, $cache ) = @_; |
133
|
|
|
|
|
|
|
|
134
|
2
|
50
|
|
|
|
8
|
$cache or |
135
|
|
|
|
|
|
|
croak( "cache required" ); |
136
|
|
|
|
|
|
|
|
137
|
2
|
|
|
|
|
5
|
my $key = 'Test Key'; |
138
|
|
|
|
|
|
|
|
139
|
2
|
|
|
|
|
4
|
my $value = 'Test Value'; |
140
|
|
|
|
|
|
|
|
141
|
2
|
|
|
|
|
7
|
$cache->set( $key, $value ); |
142
|
|
|
|
|
|
|
|
143
|
2
|
|
|
|
|
6
|
my $cache_key = 'Cache Key'; |
144
|
|
|
|
|
|
|
|
145
|
2
|
|
|
|
|
8
|
$cache->set( $cache_key, $cache ); |
146
|
|
|
|
|
|
|
|
147
|
2
|
|
|
|
|
9
|
my $fetched_cache = $cache->get( $cache_key ); |
148
|
|
|
|
|
|
|
|
149
|
2
|
50
|
|
|
|
13
|
( defined $fetched_cache ) ? |
150
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( 'defined $fetched_cache' ); |
151
|
|
|
|
|
|
|
|
152
|
2
|
|
|
|
|
10
|
my $fetched_value = $fetched_cache->get( $key ); |
153
|
|
|
|
|
|
|
|
154
|
2
|
50
|
|
|
|
17
|
( $fetched_value eq $value ) ? |
155
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$fetched_value eq $value' ); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# Test the expiration of an object |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub _test_four |
162
|
|
|
|
|
|
|
{ |
163
|
2
|
|
|
2
|
|
5
|
my ( $self, $cache ) = @_; |
164
|
|
|
|
|
|
|
|
165
|
2
|
|
|
|
|
5
|
my $expires_in = $EXPIRES_DELAY; |
166
|
|
|
|
|
|
|
|
167
|
2
|
|
|
|
|
3
|
my $key = 'Test Key'; |
168
|
|
|
|
|
|
|
|
169
|
2
|
|
|
|
|
5
|
my $value = 'Test Value'; |
170
|
|
|
|
|
|
|
|
171
|
2
|
|
|
|
|
9
|
$cache->set( $key, $value, $expires_in ); |
172
|
|
|
|
|
|
|
|
173
|
2
|
|
|
|
|
11
|
my $fetched_value = $cache->get( $key ); |
174
|
|
|
|
|
|
|
|
175
|
2
|
50
|
|
|
|
12
|
( $fetched_value eq $value ) ? |
176
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$fetched_value eq $value' ); |
177
|
|
|
|
|
|
|
|
178
|
2
|
|
|
|
|
6000368
|
sleep( $EXPIRES_DELAY + 1 ); |
179
|
|
|
|
|
|
|
|
180
|
2
|
|
|
|
|
41
|
my $fetched_expired_value = $cache->get( $key ); |
181
|
|
|
|
|
|
|
|
182
|
2
|
50
|
|
|
|
28
|
( not defined $fetched_expired_value ) ? |
183
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( 'not defined $fetched_expired_value' ); |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
# Test that caches make deep copies of values |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub _test_five |
191
|
|
|
|
|
|
|
{ |
192
|
2
|
|
|
2
|
|
6
|
my ( $self, $cache ) = @_; |
193
|
|
|
|
|
|
|
|
194
|
2
|
50
|
|
|
|
13
|
$cache or |
195
|
|
|
|
|
|
|
croak( "cache required" ); |
196
|
|
|
|
|
|
|
|
197
|
2
|
|
|
|
|
6
|
my $key = 'Test Key'; |
198
|
|
|
|
|
|
|
|
199
|
2
|
|
|
|
|
11
|
my @value_list = ( 'One', 'Two', 'Three' ); |
200
|
|
|
|
|
|
|
|
201
|
2
|
|
|
|
|
17
|
$cache->set( $key, \@value_list ); |
202
|
|
|
|
|
|
|
|
203
|
2
|
|
|
|
|
9
|
@value_list = ( ); |
204
|
|
|
|
|
|
|
|
205
|
2
|
|
|
|
|
12
|
my $fetched_value_list_ref = $cache->get( $key ); |
206
|
|
|
|
|
|
|
|
207
|
2
|
50
|
33
|
|
|
82
|
if ( ( $fetched_value_list_ref->[0] eq 'One' ) and |
|
|
|
33
|
|
|
|
|
208
|
|
|
|
|
|
|
( $fetched_value_list_ref->[1] eq 'Two' ) and |
209
|
|
|
|
|
|
|
( $fetched_value_list_ref->[2] eq 'Three' ) ) |
210
|
|
|
|
|
|
|
{ |
211
|
2
|
|
|
|
|
10
|
$self->ok( ); |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
else |
214
|
|
|
|
|
|
|
{ |
215
|
0
|
|
|
|
|
0
|
$self->not_ok( 'fetched deep list does not match set deep list' ); |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
# Test clearing a cache |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub _test_six |
224
|
|
|
|
|
|
|
{ |
225
|
2
|
|
|
2
|
|
5
|
my ( $self, $cache ) = @_; |
226
|
|
|
|
|
|
|
|
227
|
2
|
50
|
|
|
|
11
|
$cache or |
228
|
|
|
|
|
|
|
croak( "cache required" ); |
229
|
|
|
|
|
|
|
|
230
|
2
|
|
|
|
|
4
|
my $key = 'Test Key'; |
231
|
|
|
|
|
|
|
|
232
|
2
|
|
|
|
|
4
|
my $value = 'Test Value'; |
233
|
|
|
|
|
|
|
|
234
|
2
|
|
|
|
|
10
|
$cache->set( $key, $value ); |
235
|
|
|
|
|
|
|
|
236
|
2
|
|
|
|
|
35
|
$cache->clear( ); |
237
|
|
|
|
|
|
|
|
238
|
2
|
|
|
|
|
10
|
my $fetched_cleared_value = $cache->get( $key ); |
239
|
|
|
|
|
|
|
|
240
|
2
|
50
|
|
|
|
18
|
( not defined $fetched_cleared_value ) ? |
241
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( 'not defined $fetched_cleared_value' ); |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
# Test sizing of the cache |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
sub _test_seven |
248
|
|
|
|
|
|
|
{ |
249
|
2
|
|
|
2
|
|
7
|
my ( $self, $cache ) = @_; |
250
|
|
|
|
|
|
|
|
251
|
2
|
|
|
|
|
129
|
my $empty_size = $cache->size( ); |
252
|
|
|
|
|
|
|
|
253
|
2
|
50
|
|
|
|
16
|
( $empty_size == 0 ) ? |
254
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$empty_size == 0' ); |
255
|
|
|
|
|
|
|
|
256
|
2
|
|
|
|
|
6
|
my $first_key = 'First Test Key'; |
257
|
|
|
|
|
|
|
|
258
|
2
|
|
|
|
|
6
|
my $value = 'Test Value'; |
259
|
|
|
|
|
|
|
|
260
|
2
|
|
|
|
|
83
|
$cache->set( $first_key, $value ); |
261
|
|
|
|
|
|
|
|
262
|
2
|
|
|
|
|
11
|
my $first_size = $cache->size( ); |
263
|
|
|
|
|
|
|
|
264
|
2
|
50
|
|
|
|
18
|
( $first_size > $empty_size ) ? |
265
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$first_size > $empty_size' ); |
266
|
|
|
|
|
|
|
|
267
|
2
|
|
|
|
|
5
|
my $second_key = 'Second Test Key'; |
268
|
|
|
|
|
|
|
|
269
|
2
|
|
|
|
|
14
|
$cache->set( $second_key, $value ); |
270
|
|
|
|
|
|
|
|
271
|
2
|
|
|
|
|
9
|
my $second_size = $cache->size( ); |
272
|
|
|
|
|
|
|
|
273
|
2
|
50
|
|
|
|
26
|
( $second_size > $first_size ) ? |
274
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$second_size > $first_size' ); |
275
|
|
|
|
|
|
|
} |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
# Test purging the cache |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
sub _test_eight |
281
|
|
|
|
|
|
|
{ |
282
|
2
|
|
|
2
|
|
6
|
my ( $self, $cache ) = @_; |
283
|
|
|
|
|
|
|
|
284
|
2
|
|
|
|
|
56
|
$cache->clear( ); |
285
|
|
|
|
|
|
|
|
286
|
2
|
|
|
|
|
18
|
my $empty_size = $cache->size( ); |
287
|
|
|
|
|
|
|
|
288
|
2
|
50
|
|
|
|
16
|
( $empty_size == 0 ) ? |
289
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$empty_size == 0' ); |
290
|
|
|
|
|
|
|
|
291
|
2
|
|
|
|
|
8
|
my $expires_in = $EXPIRES_DELAY; |
292
|
|
|
|
|
|
|
|
293
|
2
|
|
|
|
|
5
|
my $key = 'Test Key'; |
294
|
|
|
|
|
|
|
|
295
|
2
|
|
|
|
|
5
|
my $value = 'Test Value'; |
296
|
|
|
|
|
|
|
|
297
|
2
|
|
|
|
|
10
|
$cache->set( $key, $value, $expires_in ); |
298
|
|
|
|
|
|
|
|
299
|
2
|
|
|
|
|
10
|
my $pre_purge_size = $cache->size( ); |
300
|
|
|
|
|
|
|
|
301
|
2
|
50
|
|
|
|
17
|
( $pre_purge_size > $empty_size ) ? |
302
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$pre_purge_size > $empty_size' ); |
303
|
|
|
|
|
|
|
|
304
|
2
|
|
|
|
|
6004173
|
sleep( $EXPIRES_DELAY + 1 ); |
305
|
|
|
|
|
|
|
|
306
|
2
|
|
|
|
|
135
|
$cache->purge( ); |
307
|
|
|
|
|
|
|
|
308
|
2
|
|
|
|
|
21
|
my $post_purge_size = $cache->size( ); |
309
|
|
|
|
|
|
|
|
310
|
2
|
50
|
|
|
|
30
|
( $post_purge_size == $empty_size ) ? |
311
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$post_purge_size == $empty_size' ); |
312
|
|
|
|
|
|
|
} |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
# Test the getting, setting, and removal of a scalar across cache instances |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
sub _test_nine |
318
|
|
|
|
|
|
|
{ |
319
|
2
|
|
|
2
|
|
10
|
my ( $self, $cache1 ) = @_; |
320
|
|
|
|
|
|
|
|
321
|
2
|
50
|
|
|
|
17
|
$cache1 or |
322
|
|
|
|
|
|
|
croak( "cache required" ); |
323
|
|
|
|
|
|
|
|
324
|
2
|
50
|
|
|
|
57
|
my $cache2 = $cache1->new( ) or |
325
|
|
|
|
|
|
|
croak( "Couldn't construct new cache" ); |
326
|
|
|
|
|
|
|
|
327
|
2
|
|
|
|
|
11
|
my $key = 'Test Key'; |
328
|
|
|
|
|
|
|
|
329
|
2
|
|
|
|
|
8
|
my $value = 'Test Value'; |
330
|
|
|
|
|
|
|
|
331
|
2
|
|
|
|
|
17
|
$cache1->set( $key, $value ); |
332
|
|
|
|
|
|
|
|
333
|
2
|
|
|
|
|
15
|
my $fetched_value = $cache2->get( $key ); |
334
|
|
|
|
|
|
|
|
335
|
2
|
50
|
|
|
|
117
|
( $fetched_value eq $value ) ? |
336
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$fetched_value eq $value' ); |
337
|
|
|
|
|
|
|
} |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
# Test Clear() and Size() as instance methods |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
sub _test_ten |
343
|
|
|
|
|
|
|
{ |
344
|
2
|
|
|
2
|
|
5
|
my ( $self, $cache ) = @_; |
345
|
|
|
|
|
|
|
|
346
|
2
|
50
|
|
|
|
13
|
$cache or |
347
|
|
|
|
|
|
|
croak( "cache required" ); |
348
|
|
|
|
|
|
|
|
349
|
2
|
|
|
|
|
6
|
my $key = 'Test Key'; |
350
|
|
|
|
|
|
|
|
351
|
2
|
|
|
|
|
6
|
my $value = 'Test Value'; |
352
|
|
|
|
|
|
|
|
353
|
2
|
|
|
|
|
65
|
$cache->set( $key, $value ); |
354
|
|
|
|
|
|
|
|
355
|
2
|
|
|
|
|
20
|
my $full_size = $cache->Size( ); |
356
|
|
|
|
|
|
|
|
357
|
2
|
50
|
|
|
|
23
|
( $full_size > 0 ) ? |
358
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$full_size > 0' ); |
359
|
|
|
|
|
|
|
|
360
|
2
|
|
|
|
|
13
|
$cache->Clear( ); |
361
|
|
|
|
|
|
|
|
362
|
2
|
|
|
|
|
11
|
my $empty_size = $cache->Size( ); |
363
|
|
|
|
|
|
|
|
364
|
2
|
50
|
|
|
|
17
|
( $empty_size == 0 ) ? |
365
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$empty_size == 0' ); |
366
|
|
|
|
|
|
|
} |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
# Test Purge(), Clear(), and Size() as instance methods |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
sub _test_eleven |
372
|
|
|
|
|
|
|
{ |
373
|
2
|
|
|
2
|
|
6
|
my ( $self, $cache ) = @_; |
374
|
|
|
|
|
|
|
|
375
|
2
|
|
|
|
|
11
|
$cache->Clear( ); |
376
|
|
|
|
|
|
|
|
377
|
2
|
|
|
|
|
11
|
my $empty_size = $cache->Size( ); |
378
|
|
|
|
|
|
|
|
379
|
2
|
50
|
|
|
|
25
|
( $empty_size == 0 ) ? |
380
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$empty_size == 0' ); |
381
|
|
|
|
|
|
|
|
382
|
2
|
|
|
|
|
7
|
my $expires_in = $EXPIRES_DELAY; |
383
|
|
|
|
|
|
|
|
384
|
2
|
|
|
|
|
6
|
my $key = 'Test Key'; |
385
|
|
|
|
|
|
|
|
386
|
2
|
|
|
|
|
5
|
my $value = 'Test Value'; |
387
|
|
|
|
|
|
|
|
388
|
2
|
|
|
|
|
14
|
$cache->set( $key, $value, $expires_in ); |
389
|
|
|
|
|
|
|
|
390
|
2
|
|
|
|
|
12
|
my $pre_purge_size = $cache->Size( ); |
391
|
|
|
|
|
|
|
|
392
|
2
|
50
|
|
|
|
15
|
( $pre_purge_size > $empty_size ) ? |
393
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$pre_purge_size > $empty_size' ); |
394
|
|
|
|
|
|
|
|
395
|
2
|
|
|
|
|
6000314
|
sleep( $EXPIRES_DELAY + 1 ); |
396
|
|
|
|
|
|
|
|
397
|
2
|
|
|
|
|
53
|
$cache->Purge( ); |
398
|
|
|
|
|
|
|
|
399
|
2
|
|
|
|
|
13
|
my $purged_object = $cache->get_object( $key ); |
400
|
|
|
|
|
|
|
|
401
|
2
|
50
|
|
|
|
34
|
( not defined $purged_object ) ? |
402
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( 'not defined $purged_object' ); |
403
|
|
|
|
|
|
|
} |
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
# Test Purge(), Clear(), and Size() as static methods |
407
|
|
|
|
|
|
|
|
408
|
|
|
|
|
|
|
sub _test_twelve |
409
|
|
|
|
|
|
|
{ |
410
|
2
|
|
|
2
|
|
8
|
my ( $self, $cache ) = @_; |
411
|
|
|
|
|
|
|
|
412
|
2
|
50
|
|
|
|
16
|
my $class = ref $cache or |
413
|
|
|
|
|
|
|
croak( "Couldn't get ref \$cache" ); |
414
|
|
|
|
|
|
|
|
415
|
2
|
|
|
2
|
|
15
|
no strict 'refs'; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
390
|
|
416
|
|
|
|
|
|
|
|
417
|
2
|
|
|
|
|
6
|
&{"${class}::Clear"}( ); |
|
2
|
|
|
|
|
23
|
|
418
|
|
|
|
|
|
|
|
419
|
2
|
|
|
|
|
7
|
my $empty_size = &{"${class}::Size"}( ); |
|
2
|
|
|
|
|
19
|
|
420
|
|
|
|
|
|
|
|
421
|
2
|
50
|
|
|
|
19
|
( $empty_size == 0 ) ? |
422
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$empty_size == 0' ); |
423
|
|
|
|
|
|
|
|
424
|
2
|
|
|
|
|
6
|
my $expires_in = $EXPIRES_DELAY; |
425
|
|
|
|
|
|
|
|
426
|
2
|
|
|
|
|
7
|
my $key = 'Test Key'; |
427
|
|
|
|
|
|
|
|
428
|
2
|
|
|
|
|
6
|
my $value = 'Test Value'; |
429
|
|
|
|
|
|
|
|
430
|
2
|
|
|
|
|
13
|
$cache->set( $key, $value, $expires_in ); |
431
|
|
|
|
|
|
|
|
432
|
2
|
|
|
|
|
8
|
my $pre_purge_size = &{"${class}::Size"}( ); |
|
2
|
|
|
|
|
18
|
|
433
|
|
|
|
|
|
|
|
434
|
2
|
50
|
|
|
|
17
|
( $pre_purge_size > $empty_size ) ? |
435
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$pre_purge_size > $empty_size' ); |
436
|
|
|
|
|
|
|
|
437
|
2
|
|
|
|
|
6000431
|
sleep( $EXPIRES_DELAY + 1 ); |
438
|
|
|
|
|
|
|
|
439
|
2
|
|
|
|
|
25
|
&{"${class}::Purge"}( ); |
|
2
|
|
|
|
|
68
|
|
440
|
|
|
|
|
|
|
|
441
|
2
|
|
|
|
|
20
|
my $purged_object = $cache->get_object( $key ); |
442
|
|
|
|
|
|
|
|
443
|
2
|
50
|
|
|
|
30
|
( not defined $purged_object ) ? |
444
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( 'not defined $purged_object' ); |
445
|
|
|
|
|
|
|
|
446
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1754
|
|
447
|
|
|
|
|
|
|
} |
448
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
# Test the expiration of an object with extended syntax |
452
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
sub _test_thirteen |
454
|
|
|
|
|
|
|
{ |
455
|
2
|
|
|
2
|
|
7
|
my ( $self, $cache ) = @_; |
456
|
|
|
|
|
|
|
|
457
|
2
|
|
|
|
|
6
|
my $expires_in = $EXPIRES_DELAY; |
458
|
|
|
|
|
|
|
|
459
|
2
|
|
|
|
|
6
|
my $key = 'Test Key'; |
460
|
|
|
|
|
|
|
|
461
|
2
|
|
|
|
|
5
|
my $value = 'Test Value'; |
462
|
|
|
|
|
|
|
|
463
|
2
|
|
|
|
|
16
|
$cache->set( $key, $value, $expires_in ); |
464
|
|
|
|
|
|
|
|
465
|
2
|
|
|
|
|
17
|
my $fetched_value = $cache->get( $key ); |
466
|
|
|
|
|
|
|
|
467
|
2
|
50
|
|
|
|
21
|
( $fetched_value eq $value ) ? |
468
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$fetched_value eq $value' ); |
469
|
|
|
|
|
|
|
|
470
|
2
|
|
|
|
|
6000281
|
sleep( $EXPIRES_DELAY + 1 ); |
471
|
|
|
|
|
|
|
|
472
|
2
|
|
|
|
|
63
|
my $fetched_expired_value = $cache->get( $key ); |
473
|
|
|
|
|
|
|
|
474
|
2
|
50
|
|
|
|
53
|
( not defined $fetched_expired_value ) ? |
475
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( 'not defined $fetched_expired_value' ); |
476
|
|
|
|
|
|
|
} |
477
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
# test the get_keys method |
480
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
sub _test_fourteen |
482
|
|
|
|
|
|
|
{ |
483
|
2
|
|
|
2
|
|
5
|
my ( $self, $cache ) = @_; |
484
|
|
|
|
|
|
|
|
485
|
2
|
|
|
|
|
16
|
$cache->Clear( ); |
486
|
|
|
|
|
|
|
|
487
|
2
|
|
|
|
|
12
|
my $empty_size = $cache->Size( ); |
488
|
|
|
|
|
|
|
|
489
|
2
|
50
|
|
|
|
15
|
( $empty_size == 0 ) ? |
490
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$empty_size == 0' ); |
491
|
|
|
|
|
|
|
|
492
|
2
|
|
|
|
|
17
|
my @keys = sort ( 'John', 'Paul', 'Ringo', 'George' ); |
493
|
|
|
|
|
|
|
|
494
|
2
|
|
|
|
|
6
|
my $value = 'Test Value'; |
495
|
|
|
|
|
|
|
|
496
|
2
|
|
|
|
|
6
|
foreach my $key ( @keys ) |
497
|
|
|
|
|
|
|
{ |
498
|
8
|
|
|
|
|
73
|
$cache->set( $key, $value ); |
499
|
|
|
|
|
|
|
} |
500
|
|
|
|
|
|
|
|
501
|
2
|
|
|
|
|
10
|
my @cached_keys = sort $cache->get_keys( ); |
502
|
|
|
|
|
|
|
|
503
|
2
|
|
|
|
|
14
|
my $arrays_equal = Arrays_Are_Equal( \@keys, \@cached_keys ); |
504
|
|
|
|
|
|
|
|
505
|
2
|
50
|
|
|
|
11
|
( $arrays_equal == 1 ) ? |
506
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$arrays_equal == 1' ); |
507
|
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
# test the auto_purge on set functionality |
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
sub _test_fifteen |
513
|
|
|
|
|
|
|
{ |
514
|
2
|
|
|
2
|
|
4
|
my ( $self, $cache ) = @_; |
515
|
|
|
|
|
|
|
|
516
|
2
|
|
|
|
|
11
|
$cache->Clear( ); |
517
|
|
|
|
|
|
|
|
518
|
2
|
|
|
|
|
7
|
my $expires_in = $EXPIRES_DELAY; |
519
|
|
|
|
|
|
|
|
520
|
2
|
|
|
|
|
24
|
$cache->set_auto_purge_interval( $expires_in ); |
521
|
|
|
|
|
|
|
|
522
|
2
|
|
|
|
|
9
|
$cache->set_auto_purge_on_set( 1 ); |
523
|
|
|
|
|
|
|
|
524
|
2
|
|
|
|
|
3
|
my $key = 'Test Key'; |
525
|
|
|
|
|
|
|
|
526
|
2
|
|
|
|
|
4
|
my $value = 'Test Value'; |
527
|
|
|
|
|
|
|
|
528
|
2
|
|
|
|
|
7
|
$cache->set( $key, $value, $expires_in ); |
529
|
|
|
|
|
|
|
|
530
|
2
|
|
|
|
|
11
|
my $fetched_value = $cache->get( $key ); |
531
|
|
|
|
|
|
|
|
532
|
2
|
50
|
|
|
|
12
|
( $fetched_value eq $value ) ? |
533
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$fetched_value eq $value' ); |
534
|
|
|
|
|
|
|
|
535
|
2
|
|
|
|
|
6000261
|
sleep( $EXPIRES_DELAY + 1 ); |
536
|
|
|
|
|
|
|
|
537
|
2
|
|
|
|
|
58
|
$cache->set( "Trigger auto_purge", "Empty" ); |
538
|
|
|
|
|
|
|
|
539
|
2
|
|
|
|
|
14
|
my $fetched_expired_object = $cache->get_object( $key ); |
540
|
|
|
|
|
|
|
|
541
|
2
|
50
|
|
|
|
27
|
( not defined $fetched_expired_object ) ? |
542
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( 'not defined $fetched_expired_object' ); |
543
|
|
|
|
|
|
|
|
544
|
2
|
|
|
|
|
19
|
$cache->Clear( ); |
545
|
|
|
|
|
|
|
} |
546
|
|
|
|
|
|
|
|
547
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
|
549
|
|
|
|
|
|
|
# test the auto_purge_interval functionality |
550
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
sub _test_sixteen |
552
|
|
|
|
|
|
|
{ |
553
|
2
|
|
|
2
|
|
6
|
my ( $self, $cache ) = @_; |
554
|
|
|
|
|
|
|
|
555
|
2
|
|
|
|
|
9
|
my $expires_in = $EXPIRES_DELAY; |
556
|
|
|
|
|
|
|
|
557
|
2
|
|
|
|
|
5
|
my $ok = eval { |
558
|
2
|
|
|
|
|
21
|
$cache = $cache->new( { 'auto_purge_interval' => $expires_in } ); |
559
|
2
|
|
|
|
|
11
|
1; |
560
|
|
|
|
|
|
|
}; |
561
|
|
|
|
|
|
|
|
562
|
2
|
50
|
|
|
|
21
|
$ok ? $self->ok( ) |
563
|
|
|
|
|
|
|
: $self->not_ok( "couldn't create autopurge cache" ); |
564
|
|
|
|
|
|
|
} |
565
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
# test the get_namespaces method |
568
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
sub _test_seventeen |
570
|
|
|
|
|
|
|
{ |
571
|
2
|
|
|
2
|
|
7
|
my ( $self, $cache ) = @_; |
572
|
|
|
|
|
|
|
|
573
|
2
|
|
|
|
|
14
|
$cache->set( 'a', '1' ); |
574
|
2
|
|
|
|
|
17
|
$cache->set_namespace( 'namespace' ); |
575
|
2
|
|
|
|
|
12
|
$cache->set( 'b', '2' ); |
576
|
|
|
|
|
|
|
|
577
|
2
|
50
|
|
|
|
34
|
if ( Arrays_Are_Equal( [ sort( $cache->get_namespaces( ) ) ], |
578
|
|
|
|
|
|
|
[ sort( 'Default', 'namespace' ) ] ) ) |
579
|
|
|
|
|
|
|
{ |
580
|
2
|
|
|
|
|
15
|
$self->ok( ); |
581
|
|
|
|
|
|
|
} |
582
|
|
|
|
|
|
|
else |
583
|
|
|
|
|
|
|
{ |
584
|
0
|
|
|
|
|
0
|
$self->not_ok( "get_namespaces returned the wrong namespaces" ); |
585
|
|
|
|
|
|
|
} |
586
|
|
|
|
|
|
|
|
587
|
2
|
|
|
|
|
21
|
$cache->Clear( ); |
588
|
|
|
|
|
|
|
} |
589
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
sub Arrays_Are_Equal |
593
|
|
|
|
|
|
|
{ |
594
|
4
|
|
|
4
|
0
|
10
|
my ( $first_array_ref, $second_array_ref ) = @_; |
595
|
|
|
|
|
|
|
|
596
|
4
|
|
|
|
|
29
|
local $^W = 0; # silence spurious -w undef complaints |
597
|
|
|
|
|
|
|
|
598
|
4
|
50
|
|
|
|
20
|
return 0 unless @$first_array_ref == @$second_array_ref; |
599
|
|
|
|
|
|
|
|
600
|
4
|
|
|
|
|
17
|
for (my $i = 0; $i < @$first_array_ref; $i++) |
601
|
|
|
|
|
|
|
{ |
602
|
12
|
50
|
|
|
|
45
|
return 0 if $first_array_ref->[$i] ne $second_array_ref->[$i]; |
603
|
|
|
|
|
|
|
} |
604
|
|
|
|
|
|
|
|
605
|
4
|
|
|
|
|
22
|
return 1; |
606
|
|
|
|
|
|
|
} |
607
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
1; |
610
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
__END__ |