| 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
|
4
|
|
|
4
|
|
2609
|
use strict; |
|
|
4
|
|
|
|
|
6
|
|
|
|
4
|
|
|
|
|
124
|
|
|
14
|
4
|
|
|
4
|
|
1978
|
use Cache::BaseCacheTester; |
|
|
4
|
|
|
|
|
10
|
|
|
|
4
|
|
|
|
|
94
|
|
|
15
|
4
|
|
|
4
|
|
21
|
use Cache::Cache; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
203
|
|
|
16
|
4
|
|
|
4
|
|
3972
|
use Error qw( :try ); |
|
|
4
|
|
|
|
|
26967
|
|
|
|
4
|
|
|
|
|
27
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
4
|
|
|
4
|
|
681
|
use vars qw( @ISA $EXPIRES_DELAY ); |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
7212
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
@ISA = qw ( Cache::BaseCacheTester ); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$EXPIRES_DELAY = 2; |
|
23
|
|
|
|
|
|
|
$Error::Debug = 1; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub test |
|
26
|
|
|
|
|
|
|
{ |
|
27
|
4
|
|
|
4
|
1
|
31
|
my ( $self, $cache ) = @_; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
try |
|
30
|
|
|
|
|
|
|
{ |
|
31
|
4
|
|
|
4
|
|
156
|
$cache->Clear( ); |
|
32
|
4
|
|
|
|
|
47
|
$self->_test_one( $cache ); |
|
33
|
4
|
|
|
|
|
22
|
$self->_test_two( $cache ); |
|
34
|
4
|
|
|
|
|
20
|
$self->_test_three( $cache ); |
|
35
|
4
|
|
|
|
|
26
|
$self->_test_four( $cache ); |
|
36
|
4
|
|
|
|
|
29
|
$self->_test_five( $cache ); |
|
37
|
4
|
|
|
|
|
22
|
$self->_test_six( $cache ); |
|
38
|
4
|
|
|
|
|
24
|
$self->_test_seven( $cache ); |
|
39
|
4
|
|
|
|
|
24
|
$self->_test_eight( $cache ); |
|
40
|
4
|
|
|
|
|
30
|
$self->_test_nine( $cache ); |
|
41
|
4
|
|
|
|
|
29
|
$self->_test_ten( $cache ); |
|
42
|
4
|
|
|
|
|
30
|
$self->_test_eleven( $cache ); |
|
43
|
4
|
|
|
|
|
26
|
$self->_test_twelve( $cache ); |
|
44
|
4
|
|
|
|
|
25
|
$self->_test_thirteen( $cache ); |
|
45
|
4
|
|
|
|
|
27
|
$self->_test_fourteen( $cache ); |
|
46
|
4
|
|
|
|
|
26
|
$self->_test_fifteen( $cache ); |
|
47
|
4
|
|
|
|
|
37
|
$self->_test_sixteen( $cache ); |
|
48
|
4
|
|
|
|
|
26
|
$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
|
4
|
|
|
|
|
67
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Test the getting, setting, and removal of a scalar |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _test_one |
|
65
|
|
|
|
|
|
|
{ |
|
66
|
4
|
|
|
4
|
|
10
|
my ( $self, $cache ) = @_; |
|
67
|
|
|
|
|
|
|
|
|
68
|
4
|
50
|
|
|
|
17
|
$cache or |
|
69
|
|
|
|
|
|
|
croak( "cache required" ); |
|
70
|
|
|
|
|
|
|
|
|
71
|
4
|
|
|
|
|
9
|
my $key = 'Test Key'; |
|
72
|
|
|
|
|
|
|
|
|
73
|
4
|
|
|
|
|
8
|
my $value = 'Test Value'; |
|
74
|
|
|
|
|
|
|
|
|
75
|
4
|
|
|
|
|
33
|
$cache->set( $key, $value ); |
|
76
|
|
|
|
|
|
|
|
|
77
|
4
|
|
|
|
|
49
|
my $fetched_value = $cache->get( $key ); |
|
78
|
|
|
|
|
|
|
|
|
79
|
4
|
50
|
|
|
|
52
|
( $fetched_value eq $value ) ? |
|
80
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$fetched_value eq $value' ); |
|
81
|
|
|
|
|
|
|
|
|
82
|
4
|
|
|
|
|
94
|
$cache->remove( $key ); |
|
83
|
|
|
|
|
|
|
|
|
84
|
4
|
|
|
|
|
25
|
my $fetched_removed_value = $cache->get( $key ); |
|
85
|
|
|
|
|
|
|
|
|
86
|
4
|
50
|
|
|
|
35
|
( 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
|
4
|
|
|
4
|
|
8
|
my ( $self, $cache ) = @_; |
|
96
|
|
|
|
|
|
|
|
|
97
|
4
|
50
|
|
|
|
21
|
$cache or |
|
98
|
|
|
|
|
|
|
croak( "cache required" ); |
|
99
|
|
|
|
|
|
|
|
|
100
|
4
|
|
|
|
|
10
|
my $key = 'Test Key'; |
|
101
|
|
|
|
|
|
|
|
|
102
|
4
|
|
|
|
|
12
|
my @value_list = ( 'One', 'Two', 'Three' ); |
|
103
|
|
|
|
|
|
|
|
|
104
|
4
|
|
|
|
|
46
|
$cache->set( $key, \@value_list ); |
|
105
|
|
|
|
|
|
|
|
|
106
|
4
|
|
|
|
|
28
|
my $fetched_value_list_ref = $cache->get( $key ); |
|
107
|
|
|
|
|
|
|
|
|
108
|
4
|
50
|
33
|
|
|
64
|
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
|
4
|
|
|
|
|
20
|
$self->ok( ); |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
else |
|
115
|
|
|
|
|
|
|
{ |
|
116
|
0
|
|
|
|
|
0
|
$self->not_ok( 'fetched list does not match set list' ); |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
4
|
|
|
|
|
20
|
$cache->remove( $key ); |
|
120
|
|
|
|
|
|
|
|
|
121
|
4
|
|
|
|
|
22
|
my $fetched_removed_value = $cache->get( $key ); |
|
122
|
|
|
|
|
|
|
|
|
123
|
4
|
50
|
|
|
|
33
|
( 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
|
4
|
|
|
4
|
|
8
|
my ( $self, $cache ) = @_; |
|
133
|
|
|
|
|
|
|
|
|
134
|
4
|
50
|
|
|
|
15
|
$cache or |
|
135
|
|
|
|
|
|
|
croak( "cache required" ); |
|
136
|
|
|
|
|
|
|
|
|
137
|
4
|
|
|
|
|
13
|
my $key = 'Test Key'; |
|
138
|
|
|
|
|
|
|
|
|
139
|
4
|
|
|
|
|
6
|
my $value = 'Test Value'; |
|
140
|
|
|
|
|
|
|
|
|
141
|
4
|
|
|
|
|
18
|
$cache->set( $key, $value ); |
|
142
|
|
|
|
|
|
|
|
|
143
|
4
|
|
|
|
|
19
|
my $cache_key = 'Cache Key'; |
|
144
|
|
|
|
|
|
|
|
|
145
|
4
|
|
|
|
|
20
|
$cache->set( $cache_key, $cache ); |
|
146
|
|
|
|
|
|
|
|
|
147
|
4
|
|
|
|
|
28
|
my $fetched_cache = $cache->get( $cache_key ); |
|
148
|
|
|
|
|
|
|
|
|
149
|
4
|
50
|
|
|
|
32
|
( defined $fetched_cache ) ? |
|
150
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( 'defined $fetched_cache' ); |
|
151
|
|
|
|
|
|
|
|
|
152
|
4
|
|
|
|
|
19
|
my $fetched_value = $fetched_cache->get( $key ); |
|
153
|
|
|
|
|
|
|
|
|
154
|
4
|
50
|
|
|
|
33
|
( $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
|
4
|
|
|
4
|
|
11
|
my ( $self, $cache ) = @_; |
|
164
|
|
|
|
|
|
|
|
|
165
|
4
|
|
|
|
|
12
|
my $expires_in = $EXPIRES_DELAY; |
|
166
|
|
|
|
|
|
|
|
|
167
|
4
|
|
|
|
|
10
|
my $key = 'Test Key'; |
|
168
|
|
|
|
|
|
|
|
|
169
|
4
|
|
|
|
|
10
|
my $value = 'Test Value'; |
|
170
|
|
|
|
|
|
|
|
|
171
|
4
|
|
|
|
|
24
|
$cache->set( $key, $value, $expires_in ); |
|
172
|
|
|
|
|
|
|
|
|
173
|
4
|
|
|
|
|
28
|
my $fetched_value = $cache->get( $key ); |
|
174
|
|
|
|
|
|
|
|
|
175
|
4
|
50
|
|
|
|
27
|
( $fetched_value eq $value ) ? |
|
176
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$fetched_value eq $value' ); |
|
177
|
|
|
|
|
|
|
|
|
178
|
4
|
|
|
|
|
12000676
|
sleep( $EXPIRES_DELAY + 1 ); |
|
179
|
|
|
|
|
|
|
|
|
180
|
4
|
|
|
|
|
70
|
my $fetched_expired_value = $cache->get( $key ); |
|
181
|
|
|
|
|
|
|
|
|
182
|
4
|
50
|
|
|
|
46
|
( 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
|
4
|
|
|
4
|
|
10
|
my ( $self, $cache ) = @_; |
|
193
|
|
|
|
|
|
|
|
|
194
|
4
|
50
|
|
|
|
22
|
$cache or |
|
195
|
|
|
|
|
|
|
croak( "cache required" ); |
|
196
|
|
|
|
|
|
|
|
|
197
|
4
|
|
|
|
|
11
|
my $key = 'Test Key'; |
|
198
|
|
|
|
|
|
|
|
|
199
|
4
|
|
|
|
|
16
|
my @value_list = ( 'One', 'Two', 'Three' ); |
|
200
|
|
|
|
|
|
|
|
|
201
|
4
|
|
|
|
|
28
|
$cache->set( $key, \@value_list ); |
|
202
|
|
|
|
|
|
|
|
|
203
|
4
|
|
|
|
|
16
|
@value_list = ( ); |
|
204
|
|
|
|
|
|
|
|
|
205
|
4
|
|
|
|
|
18
|
my $fetched_value_list_ref = $cache->get( $key ); |
|
206
|
|
|
|
|
|
|
|
|
207
|
4
|
50
|
33
|
|
|
58
|
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
|
4
|
|
|
|
|
22
|
$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
|
4
|
|
|
4
|
|
11
|
my ( $self, $cache ) = @_; |
|
226
|
|
|
|
|
|
|
|
|
227
|
4
|
50
|
|
|
|
21
|
$cache or |
|
228
|
|
|
|
|
|
|
croak( "cache required" ); |
|
229
|
|
|
|
|
|
|
|
|
230
|
4
|
|
|
|
|
12
|
my $key = 'Test Key'; |
|
231
|
|
|
|
|
|
|
|
|
232
|
4
|
|
|
|
|
7
|
my $value = 'Test Value'; |
|
233
|
|
|
|
|
|
|
|
|
234
|
4
|
|
|
|
|
22
|
$cache->set( $key, $value ); |
|
235
|
|
|
|
|
|
|
|
|
236
|
4
|
|
|
|
|
54
|
$cache->clear( ); |
|
237
|
|
|
|
|
|
|
|
|
238
|
4
|
|
|
|
|
31
|
my $fetched_cleared_value = $cache->get( $key ); |
|
239
|
|
|
|
|
|
|
|
|
240
|
4
|
50
|
|
|
|
39
|
( 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
|
4
|
|
|
4
|
|
12
|
my ( $self, $cache ) = @_; |
|
250
|
|
|
|
|
|
|
|
|
251
|
4
|
|
|
|
|
46
|
my $empty_size = $cache->size( ); |
|
252
|
|
|
|
|
|
|
|
|
253
|
4
|
50
|
|
|
|
31
|
( $empty_size == 0 ) ? |
|
254
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$empty_size == 0' ); |
|
255
|
|
|
|
|
|
|
|
|
256
|
4
|
|
|
|
|
11
|
my $first_key = 'First Test Key'; |
|
257
|
|
|
|
|
|
|
|
|
258
|
4
|
|
|
|
|
14
|
my $value = 'Test Value'; |
|
259
|
|
|
|
|
|
|
|
|
260
|
4
|
|
|
|
|
23
|
$cache->set( $first_key, $value ); |
|
261
|
|
|
|
|
|
|
|
|
262
|
4
|
|
|
|
|
28
|
my $first_size = $cache->size( ); |
|
263
|
|
|
|
|
|
|
|
|
264
|
4
|
50
|
|
|
|
30
|
( $first_size > $empty_size ) ? |
|
265
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$first_size > $empty_size' ); |
|
266
|
|
|
|
|
|
|
|
|
267
|
4
|
|
|
|
|
9
|
my $second_key = 'Second Test Key'; |
|
268
|
|
|
|
|
|
|
|
|
269
|
4
|
|
|
|
|
28
|
$cache->set( $second_key, $value ); |
|
270
|
|
|
|
|
|
|
|
|
271
|
4
|
|
|
|
|
27
|
my $second_size = $cache->size( ); |
|
272
|
|
|
|
|
|
|
|
|
273
|
4
|
50
|
|
|
|
433
|
( $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
|
4
|
|
|
4
|
|
8
|
my ( $self, $cache ) = @_; |
|
283
|
|
|
|
|
|
|
|
|
284
|
4
|
|
|
|
|
26
|
$cache->clear( ); |
|
285
|
|
|
|
|
|
|
|
|
286
|
4
|
|
|
|
|
28
|
my $empty_size = $cache->size( ); |
|
287
|
|
|
|
|
|
|
|
|
288
|
4
|
50
|
|
|
|
39
|
( $empty_size == 0 ) ? |
|
289
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$empty_size == 0' ); |
|
290
|
|
|
|
|
|
|
|
|
291
|
4
|
|
|
|
|
11
|
my $expires_in = $EXPIRES_DELAY; |
|
292
|
|
|
|
|
|
|
|
|
293
|
4
|
|
|
|
|
11
|
my $key = 'Test Key'; |
|
294
|
|
|
|
|
|
|
|
|
295
|
4
|
|
|
|
|
10
|
my $value = 'Test Value'; |
|
296
|
|
|
|
|
|
|
|
|
297
|
4
|
|
|
|
|
24
|
$cache->set( $key, $value, $expires_in ); |
|
298
|
|
|
|
|
|
|
|
|
299
|
4
|
|
|
|
|
25
|
my $pre_purge_size = $cache->size( ); |
|
300
|
|
|
|
|
|
|
|
|
301
|
4
|
50
|
|
|
|
30
|
( $pre_purge_size > $empty_size ) ? |
|
302
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$pre_purge_size > $empty_size' ); |
|
303
|
|
|
|
|
|
|
|
|
304
|
4
|
|
|
|
|
12001506
|
sleep( $EXPIRES_DELAY + 1 ); |
|
305
|
|
|
|
|
|
|
|
|
306
|
4
|
|
|
|
|
166
|
$cache->purge( ); |
|
307
|
|
|
|
|
|
|
|
|
308
|
4
|
|
|
|
|
31
|
my $post_purge_size = $cache->size( ); |
|
309
|
|
|
|
|
|
|
|
|
310
|
4
|
50
|
|
|
|
113
|
( $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
|
4
|
|
|
4
|
|
13
|
my ( $self, $cache1 ) = @_; |
|
320
|
|
|
|
|
|
|
|
|
321
|
4
|
50
|
|
|
|
23
|
$cache1 or |
|
322
|
|
|
|
|
|
|
croak( "cache required" ); |
|
323
|
|
|
|
|
|
|
|
|
324
|
4
|
50
|
|
|
|
60
|
my $cache2 = $cache1->new( ) or |
|
325
|
|
|
|
|
|
|
croak( "Couldn't construct new cache" ); |
|
326
|
|
|
|
|
|
|
|
|
327
|
4
|
|
|
|
|
12
|
my $key = 'Test Key'; |
|
328
|
|
|
|
|
|
|
|
|
329
|
4
|
|
|
|
|
12
|
my $value = 'Test Value'; |
|
330
|
|
|
|
|
|
|
|
|
331
|
4
|
|
|
|
|
27
|
$cache1->set( $key, $value ); |
|
332
|
|
|
|
|
|
|
|
|
333
|
4
|
|
|
|
|
34
|
my $fetched_value = $cache2->get( $key ); |
|
334
|
|
|
|
|
|
|
|
|
335
|
4
|
50
|
|
|
|
136
|
( $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
|
4
|
|
|
4
|
|
14
|
my ( $self, $cache ) = @_; |
|
345
|
|
|
|
|
|
|
|
|
346
|
4
|
50
|
|
|
|
23
|
$cache or |
|
347
|
|
|
|
|
|
|
croak( "cache required" ); |
|
348
|
|
|
|
|
|
|
|
|
349
|
4
|
|
|
|
|
13
|
my $key = 'Test Key'; |
|
350
|
|
|
|
|
|
|
|
|
351
|
4
|
|
|
|
|
10
|
my $value = 'Test Value'; |
|
352
|
|
|
|
|
|
|
|
|
353
|
4
|
|
|
|
|
24
|
$cache->set( $key, $value ); |
|
354
|
|
|
|
|
|
|
|
|
355
|
4
|
|
|
|
|
41
|
my $full_size = $cache->Size( ); |
|
356
|
|
|
|
|
|
|
|
|
357
|
4
|
50
|
|
|
|
46
|
( $full_size > 0 ) ? |
|
358
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$full_size > 0' ); |
|
359
|
|
|
|
|
|
|
|
|
360
|
4
|
|
|
|
|
28
|
$cache->Clear( ); |
|
361
|
|
|
|
|
|
|
|
|
362
|
4
|
|
|
|
|
32
|
my $empty_size = $cache->Size( ); |
|
363
|
|
|
|
|
|
|
|
|
364
|
4
|
50
|
|
|
|
257
|
( $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
|
4
|
|
|
4
|
|
14
|
my ( $self, $cache ) = @_; |
|
374
|
|
|
|
|
|
|
|
|
375
|
4
|
|
|
|
|
23
|
$cache->Clear( ); |
|
376
|
|
|
|
|
|
|
|
|
377
|
4
|
|
|
|
|
102
|
my $empty_size = $cache->Size( ); |
|
378
|
|
|
|
|
|
|
|
|
379
|
4
|
50
|
|
|
|
38
|
( $empty_size == 0 ) ? |
|
380
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$empty_size == 0' ); |
|
381
|
|
|
|
|
|
|
|
|
382
|
4
|
|
|
|
|
11
|
my $expires_in = $EXPIRES_DELAY; |
|
383
|
|
|
|
|
|
|
|
|
384
|
4
|
|
|
|
|
819
|
my $key = 'Test Key'; |
|
385
|
|
|
|
|
|
|
|
|
386
|
4
|
|
|
|
|
22
|
my $value = 'Test Value'; |
|
387
|
|
|
|
|
|
|
|
|
388
|
4
|
|
|
|
|
27
|
$cache->set( $key, $value, $expires_in ); |
|
389
|
|
|
|
|
|
|
|
|
390
|
4
|
|
|
|
|
29
|
my $pre_purge_size = $cache->Size( ); |
|
391
|
|
|
|
|
|
|
|
|
392
|
4
|
50
|
|
|
|
36
|
( $pre_purge_size > $empty_size ) ? |
|
393
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$pre_purge_size > $empty_size' ); |
|
394
|
|
|
|
|
|
|
|
|
395
|
4
|
|
|
|
|
12000579
|
sleep( $EXPIRES_DELAY + 1 ); |
|
396
|
|
|
|
|
|
|
|
|
397
|
4
|
|
|
|
|
92
|
$cache->Purge( ); |
|
398
|
|
|
|
|
|
|
|
|
399
|
4
|
|
|
|
|
36
|
my $purged_object = $cache->get_object( $key ); |
|
400
|
|
|
|
|
|
|
|
|
401
|
4
|
50
|
|
|
|
48
|
( 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
|
4
|
|
|
4
|
|
9
|
my ( $self, $cache ) = @_; |
|
411
|
|
|
|
|
|
|
|
|
412
|
4
|
50
|
|
|
|
23
|
my $class = ref $cache or |
|
413
|
|
|
|
|
|
|
croak( "Couldn't get ref \$cache" ); |
|
414
|
|
|
|
|
|
|
|
|
415
|
4
|
|
|
4
|
|
27
|
no strict 'refs'; |
|
|
4
|
|
|
|
|
16
|
|
|
|
4
|
|
|
|
|
877
|
|
|
416
|
|
|
|
|
|
|
|
|
417
|
4
|
|
|
|
|
9
|
&{"${class}::Clear"}( ); |
|
|
4
|
|
|
|
|
37
|
|
|
418
|
|
|
|
|
|
|
|
|
419
|
4
|
|
|
|
|
20
|
my $empty_size = &{"${class}::Size"}( ); |
|
|
4
|
|
|
|
|
39
|
|
|
420
|
|
|
|
|
|
|
|
|
421
|
4
|
50
|
|
|
|
34
|
( $empty_size == 0 ) ? |
|
422
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$empty_size == 0' ); |
|
423
|
|
|
|
|
|
|
|
|
424
|
4
|
|
|
|
|
16
|
my $expires_in = $EXPIRES_DELAY; |
|
425
|
|
|
|
|
|
|
|
|
426
|
4
|
|
|
|
|
12
|
my $key = 'Test Key'; |
|
427
|
|
|
|
|
|
|
|
|
428
|
4
|
|
|
|
|
14
|
my $value = 'Test Value'; |
|
429
|
|
|
|
|
|
|
|
|
430
|
4
|
|
|
|
|
28
|
$cache->set( $key, $value, $expires_in ); |
|
431
|
|
|
|
|
|
|
|
|
432
|
4
|
|
|
|
|
15
|
my $pre_purge_size = &{"${class}::Size"}( ); |
|
|
4
|
|
|
|
|
34
|
|
|
433
|
|
|
|
|
|
|
|
|
434
|
4
|
50
|
|
|
|
34
|
( $pre_purge_size > $empty_size ) ? |
|
435
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$pre_purge_size > $empty_size' ); |
|
436
|
|
|
|
|
|
|
|
|
437
|
4
|
|
|
|
|
12001066
|
sleep( $EXPIRES_DELAY + 1 ); |
|
438
|
|
|
|
|
|
|
|
|
439
|
4
|
|
|
|
|
39
|
&{"${class}::Purge"}( ); |
|
|
4
|
|
|
|
|
105
|
|
|
440
|
|
|
|
|
|
|
|
|
441
|
4
|
|
|
|
|
26
|
my $purged_object = $cache->get_object( $key ); |
|
442
|
|
|
|
|
|
|
|
|
443
|
4
|
50
|
|
|
|
45
|
( not defined $purged_object ) ? |
|
444
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( 'not defined $purged_object' ); |
|
445
|
|
|
|
|
|
|
|
|
446
|
4
|
|
|
4
|
|
22
|
use strict; |
|
|
4
|
|
|
|
|
6
|
|
|
|
4
|
|
|
|
|
3803
|
|
|
447
|
|
|
|
|
|
|
} |
|
448
|
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
# Test the expiration of an object with extended syntax |
|
452
|
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
sub _test_thirteen |
|
454
|
|
|
|
|
|
|
{ |
|
455
|
4
|
|
|
4
|
|
9
|
my ( $self, $cache ) = @_; |
|
456
|
|
|
|
|
|
|
|
|
457
|
4
|
|
|
|
|
10
|
my $expires_in = $EXPIRES_DELAY; |
|
458
|
|
|
|
|
|
|
|
|
459
|
4
|
|
|
|
|
10
|
my $key = 'Test Key'; |
|
460
|
|
|
|
|
|
|
|
|
461
|
4
|
|
|
|
|
10
|
my $value = 'Test Value'; |
|
462
|
|
|
|
|
|
|
|
|
463
|
4
|
|
|
|
|
31
|
$cache->set( $key, $value, $expires_in ); |
|
464
|
|
|
|
|
|
|
|
|
465
|
4
|
|
|
|
|
30
|
my $fetched_value = $cache->get( $key ); |
|
466
|
|
|
|
|
|
|
|
|
467
|
4
|
50
|
|
|
|
38
|
( $fetched_value eq $value ) ? |
|
468
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$fetched_value eq $value' ); |
|
469
|
|
|
|
|
|
|
|
|
470
|
4
|
|
|
|
|
12009119
|
sleep( $EXPIRES_DELAY + 1 ); |
|
471
|
|
|
|
|
|
|
|
|
472
|
4
|
|
|
|
|
100
|
my $fetched_expired_value = $cache->get( $key ); |
|
473
|
|
|
|
|
|
|
|
|
474
|
4
|
50
|
|
|
|
80
|
( 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
|
4
|
|
|
4
|
|
56
|
my ( $self, $cache ) = @_; |
|
484
|
|
|
|
|
|
|
|
|
485
|
4
|
|
|
|
|
271
|
$cache->Clear( ); |
|
486
|
|
|
|
|
|
|
|
|
487
|
4
|
|
|
|
|
32
|
my $empty_size = $cache->Size( ); |
|
488
|
|
|
|
|
|
|
|
|
489
|
4
|
50
|
|
|
|
409
|
( $empty_size == 0 ) ? |
|
490
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$empty_size == 0' ); |
|
491
|
|
|
|
|
|
|
|
|
492
|
4
|
|
|
|
|
40
|
my @keys = sort ( 'John', 'Paul', 'Ringo', 'George' ); |
|
493
|
|
|
|
|
|
|
|
|
494
|
4
|
|
|
|
|
13
|
my $value = 'Test Value'; |
|
495
|
|
|
|
|
|
|
|
|
496
|
4
|
|
|
|
|
13
|
foreach my $key ( @keys ) |
|
497
|
|
|
|
|
|
|
{ |
|
498
|
16
|
|
|
|
|
77
|
$cache->set( $key, $value ); |
|
499
|
|
|
|
|
|
|
} |
|
500
|
|
|
|
|
|
|
|
|
501
|
4
|
|
|
|
|
28
|
my @cached_keys = sort $cache->get_keys( ); |
|
502
|
|
|
|
|
|
|
|
|
503
|
4
|
|
|
|
|
30
|
my $arrays_equal = Arrays_Are_Equal( \@keys, \@cached_keys ); |
|
504
|
|
|
|
|
|
|
|
|
505
|
4
|
50
|
|
|
|
35
|
( $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
|
4
|
|
|
4
|
|
15
|
my ( $self, $cache ) = @_; |
|
515
|
|
|
|
|
|
|
|
|
516
|
4
|
|
|
|
|
29
|
$cache->Clear( ); |
|
517
|
|
|
|
|
|
|
|
|
518
|
4
|
|
|
|
|
20
|
my $expires_in = $EXPIRES_DELAY; |
|
519
|
|
|
|
|
|
|
|
|
520
|
4
|
|
|
|
|
65
|
$cache->set_auto_purge_interval( $expires_in ); |
|
521
|
|
|
|
|
|
|
|
|
522
|
4
|
|
|
|
|
21
|
$cache->set_auto_purge_on_set( 1 ); |
|
523
|
|
|
|
|
|
|
|
|
524
|
4
|
|
|
|
|
9
|
my $key = 'Test Key'; |
|
525
|
|
|
|
|
|
|
|
|
526
|
4
|
|
|
|
|
9
|
my $value = 'Test Value'; |
|
527
|
|
|
|
|
|
|
|
|
528
|
4
|
|
|
|
|
23
|
$cache->set( $key, $value, $expires_in ); |
|
529
|
|
|
|
|
|
|
|
|
530
|
4
|
|
|
|
|
28
|
my $fetched_value = $cache->get( $key ); |
|
531
|
|
|
|
|
|
|
|
|
532
|
4
|
50
|
|
|
|
35
|
( $fetched_value eq $value ) ? |
|
533
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( '$fetched_value eq $value' ); |
|
534
|
|
|
|
|
|
|
|
|
535
|
4
|
|
|
|
|
12000479
|
sleep( $EXPIRES_DELAY + 1 ); |
|
536
|
|
|
|
|
|
|
|
|
537
|
4
|
|
|
|
|
63
|
$cache->set( "Trigger auto_purge", "Empty" ); |
|
538
|
|
|
|
|
|
|
|
|
539
|
4
|
|
|
|
|
27
|
my $fetched_expired_object = $cache->get_object( $key ); |
|
540
|
|
|
|
|
|
|
|
|
541
|
4
|
50
|
|
|
|
47
|
( not defined $fetched_expired_object ) ? |
|
542
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( 'not defined $fetched_expired_object' ); |
|
543
|
|
|
|
|
|
|
|
|
544
|
4
|
|
|
|
|
29
|
$cache->Clear( ); |
|
545
|
|
|
|
|
|
|
} |
|
546
|
|
|
|
|
|
|
|
|
547
|
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
|
|
549
|
|
|
|
|
|
|
# test the auto_purge_interval functionality |
|
550
|
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
sub _test_sixteen |
|
552
|
|
|
|
|
|
|
{ |
|
553
|
4
|
|
|
4
|
|
9
|
my ( $self, $cache ) = @_; |
|
554
|
|
|
|
|
|
|
|
|
555
|
4
|
|
|
|
|
10
|
my $expires_in = $EXPIRES_DELAY; |
|
556
|
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
eval |
|
558
|
4
|
|
|
|
|
12
|
{ |
|
559
|
4
|
|
|
|
|
29
|
$cache = $cache->new( { 'auto_purge_interval' => $expires_in } ); |
|
560
|
|
|
|
|
|
|
}; |
|
561
|
|
|
|
|
|
|
|
|
562
|
4
|
50
|
|
|
|
34
|
( not defined @$ ) ? |
|
563
|
|
|
|
|
|
|
$self->ok( ) : $self->not_ok( "couldn't create autopurge cache" ); |
|
564
|
|
|
|
|
|
|
} |
|
565
|
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
# test the get_namespaces method |
|
568
|
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
sub _test_seventeen |
|
570
|
|
|
|
|
|
|
{ |
|
571
|
4
|
|
|
4
|
|
12
|
my ( $self, $cache ) = @_; |
|
572
|
|
|
|
|
|
|
|
|
573
|
4
|
|
|
|
|
24
|
$cache->set( 'a', '1' ); |
|
574
|
4
|
|
|
|
|
25
|
$cache->set_namespace( 'namespace' ); |
|
575
|
4
|
|
|
|
|
19
|
$cache->set( 'b', '2' ); |
|
576
|
|
|
|
|
|
|
|
|
577
|
4
|
50
|
|
|
|
59
|
if ( Arrays_Are_Equal( [ sort( $cache->get_namespaces( ) ) ], |
|
578
|
|
|
|
|
|
|
[ sort( 'Default', 'namespace' ) ] ) ) |
|
579
|
|
|
|
|
|
|
{ |
|
580
|
4
|
|
|
|
|
21
|
$self->ok( ); |
|
581
|
|
|
|
|
|
|
} |
|
582
|
|
|
|
|
|
|
else |
|
583
|
|
|
|
|
|
|
{ |
|
584
|
0
|
|
|
|
|
0
|
$self->not_ok( "get_namespaces returned the wrong namespaces" ); |
|
585
|
|
|
|
|
|
|
} |
|
586
|
|
|
|
|
|
|
|
|
587
|
4
|
|
|
|
|
42
|
$cache->Clear( ); |
|
588
|
|
|
|
|
|
|
} |
|
589
|
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
sub Arrays_Are_Equal |
|
593
|
|
|
|
|
|
|
{ |
|
594
|
8
|
|
|
8
|
0
|
21
|
my ( $first_array_ref, $second_array_ref ) = @_; |
|
595
|
|
|
|
|
|
|
|
|
596
|
8
|
|
|
|
|
45
|
local $^W = 0; # silence spurious -w undef complaints |
|
597
|
|
|
|
|
|
|
|
|
598
|
8
|
50
|
|
|
|
37
|
return 0 unless @$first_array_ref == @$second_array_ref; |
|
599
|
|
|
|
|
|
|
|
|
600
|
8
|
|
|
|
|
38
|
for (my $i = 0; $i < @$first_array_ref; $i++) |
|
601
|
|
|
|
|
|
|
{ |
|
602
|
24
|
50
|
|
|
|
96
|
return 0 if $first_array_ref->[$i] ne $second_array_ref->[$i]; |
|
603
|
|
|
|
|
|
|
} |
|
604
|
|
|
|
|
|
|
|
|
605
|
8
|
|
|
|
|
43
|
return 1; |
|
606
|
|
|
|
|
|
|
} |
|
607
|
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
1; |
|
610
|
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
__END__ |