| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package CHI::t::Driver::Memory; |
|
2
|
|
|
|
|
|
|
$CHI::t::Driver::Memory::VERSION = '0.61'; |
|
3
|
3
|
|
|
3
|
|
452
|
use strict; |
|
|
3
|
|
|
|
|
11
|
|
|
|
3
|
|
|
|
|
91
|
|
|
4
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
1258
|
|
|
5
|
3
|
|
|
3
|
|
410
|
use CHI::Test; |
|
|
3
|
|
|
|
|
9
|
|
|
|
3
|
|
|
|
|
18
|
|
|
6
|
3
|
|
|
3
|
|
1627
|
use CHI::Test::Driver::Role::CheckKeyValidity; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
87
|
|
|
7
|
3
|
|
|
3
|
|
3312
|
use Test::Warn; |
|
|
3
|
|
|
|
|
7620
|
|
|
|
3
|
|
|
|
|
229
|
|
|
8
|
3
|
|
|
3
|
|
28
|
use base qw(CHI::t::Driver); |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
2315
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Skip multiple process test |
|
11
|
|
|
|
3
|
0
|
|
sub test_multiple_processes { } |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new_cache_options { |
|
14
|
276
|
|
|
276
|
0
|
589
|
my $self = shift; |
|
15
|
|
|
|
|
|
|
|
|
16
|
276
|
|
|
|
|
1159
|
return ( $self->SUPER::new_cache_options(), global => 1 ); |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new_cache { |
|
20
|
182
|
|
|
182
|
0
|
441
|
my $self = shift; |
|
21
|
|
|
|
|
|
|
|
|
22
|
182
|
|
|
|
|
779
|
my %params = ( $self->new_cache_options(), @_ ); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# If new_cache called with datastore, ignore global flag (otherwise would be an error) |
|
25
|
|
|
|
|
|
|
# |
|
26
|
182
|
100
|
|
|
|
840
|
if ( $params{datastore} ) { |
|
27
|
6
|
|
|
|
|
13
|
delete $params{global}; |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Check test key validity on every get and set - only necessary to do for one driver |
|
31
|
|
|
|
|
|
|
# |
|
32
|
182
|
|
|
|
|
685
|
$params{roles} = ['+CHI::Test::Driver::Role::CheckKeyValidity']; |
|
33
|
182
|
|
|
|
|
483
|
$params{test_object} = $self; |
|
34
|
|
|
|
|
|
|
|
|
35
|
182
|
|
|
|
|
1282
|
my $cache = CHI->new(%params); |
|
36
|
182
|
|
|
|
|
1713
|
return $cache; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub test_short_driver_name : Tests { |
|
40
|
1
|
|
|
1
|
0
|
679
|
my ($self) = @_; |
|
41
|
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
4
|
my $cache = $self->{cache}; |
|
43
|
1
|
|
|
|
|
26
|
is( $cache->short_driver_name, 'Memory' ); |
|
44
|
3
|
|
|
3
|
|
24
|
} |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
14
|
|
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Warn if global or datastore not passed, but still use global datastore by default |
|
47
|
|
|
|
|
|
|
# |
|
48
|
|
|
|
|
|
|
sub test_global_or_datastore_required : Tests { |
|
49
|
3
|
|
|
3
|
0
|
2379
|
my ( $cache, $cache2 ); |
|
50
|
3
|
|
|
3
|
|
204
|
warning_like( sub { $cache = CHI->new( driver => 'Memory' ) }, |
|
51
|
3
|
|
|
|
|
45
|
qr/must specify either/ ); |
|
52
|
3
|
|
|
3
|
|
167
|
warning_like( sub { $cache2 = CHI->new( driver => 'Memory' ) }, |
|
53
|
3
|
|
|
|
|
1755
|
qr/must specify either/ ); |
|
54
|
3
|
|
|
|
|
1656
|
$cache->set( 'foo', 5 ); |
|
55
|
3
|
|
|
|
|
45
|
is( $cache2->get('foo'), 5, "defaulted to global datastore" ); |
|
56
|
3
|
|
|
3
|
|
1323
|
} |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
14
|
|
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Make sure two caches don't share datastore |
|
59
|
|
|
|
|
|
|
# |
|
60
|
|
|
|
|
|
|
sub test_different_datastores : Tests { |
|
61
|
3
|
|
|
3
|
0
|
2153
|
my $self = shift; |
|
62
|
3
|
|
|
|
|
18
|
my $cache1 = CHI->new( driver => 'Memory', datastore => {} ); |
|
63
|
3
|
|
|
|
|
19
|
my $cache2 = CHI->new( driver => 'Memory', datastore => {} ); |
|
64
|
3
|
|
|
|
|
33
|
$self->set_some_keys($cache1); |
|
65
|
3
|
|
|
|
|
34
|
ok( !$cache2->get_keys() ); |
|
66
|
3
|
|
|
3
|
|
974
|
} |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
15
|
|
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Make sure two global=0 caches don't share datastore |
|
69
|
|
|
|
|
|
|
# |
|
70
|
|
|
|
|
|
|
sub test_different_global_0 : Tests { |
|
71
|
3
|
|
|
3
|
0
|
2274
|
my $self = shift; |
|
72
|
3
|
|
|
|
|
20
|
my $cache1 = CHI->new( driver => 'Memory', global => 0 ); |
|
73
|
3
|
|
|
|
|
18
|
my $cache2 = CHI->new( driver => 'Memory', global => 0 ); |
|
74
|
3
|
|
|
|
|
23
|
$self->set_some_keys($cache1); |
|
75
|
3
|
|
|
|
|
20
|
ok( !$cache2->get_keys() ); |
|
76
|
3
|
|
|
3
|
|
984
|
} |
|
|
3
|
|
|
|
|
36
|
|
|
|
3
|
|
|
|
|
25
|
|
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Make sure cache is cleared when datastore itself is cleared |
|
79
|
|
|
|
|
|
|
# |
|
80
|
|
|
|
|
|
|
sub test_clear_datastore : Tests { |
|
81
|
3
|
|
|
3
|
0
|
2277
|
my $self = shift; |
|
82
|
3
|
|
|
|
|
24
|
$self->num_tests( $self->{key_count} * 3 + 6 ); |
|
83
|
|
|
|
|
|
|
|
|
84
|
3
|
|
|
|
|
324
|
my (@caches); |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my %datastore; |
|
87
|
3
|
|
|
|
|
18
|
$caches[0] = |
|
88
|
|
|
|
|
|
|
$self->new_cache( namespace => 'name', datastore => \%datastore ); |
|
89
|
3
|
|
|
|
|
18
|
$caches[1] = |
|
90
|
|
|
|
|
|
|
$self->new_cache( namespace => 'other', datastore => \%datastore ); |
|
91
|
3
|
|
|
|
|
92
|
$caches[2] = |
|
92
|
|
|
|
|
|
|
$self->new_cache( namespace => 'name', datastore => \%datastore ); |
|
93
|
3
|
|
|
|
|
26
|
$self->set_some_keys( $caches[0] ); |
|
94
|
3
|
|
|
|
|
18
|
$self->set_some_keys( $caches[1] ); |
|
95
|
3
|
|
|
|
|
46
|
%datastore = (); |
|
96
|
|
|
|
|
|
|
|
|
97
|
3
|
|
|
|
|
20
|
foreach my $i ( 0 .. 2 ) { |
|
98
|
9
|
|
|
|
|
57
|
$self->_verify_cache_is_cleared( $caches[$i], |
|
99
|
|
|
|
|
|
|
"cache $i after out of scope" ); |
|
100
|
|
|
|
|
|
|
} |
|
101
|
3
|
|
|
3
|
|
1330
|
} |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
16
|
|
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub test_lru_discard : Tests { |
|
104
|
2
|
|
|
2
|
0
|
1544
|
my $self = shift; |
|
105
|
2
|
50
|
|
|
|
16
|
return 'author testing only' unless ( $ENV{AUTHOR_TESTING} ); |
|
106
|
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
0
|
my $cache = $self->new_cleared_cache( max_size => 41 ); |
|
108
|
0
|
|
|
|
|
0
|
is( $cache->discard_policy, 'lru' ); |
|
109
|
0
|
|
|
|
|
0
|
my $value_20 = 'x' x 6; |
|
110
|
0
|
|
|
|
|
0
|
foreach my $key ( map { "key$_" } (qw(1 2 3 4 5 6 5 6 5 3 2)) ) { |
|
|
0
|
|
|
|
|
0
|
|
|
111
|
0
|
|
|
|
|
0
|
$cache->set( $key, $value_20 ); |
|
112
|
|
|
|
|
|
|
} |
|
113
|
0
|
|
|
|
|
0
|
cmp_set( [ $cache->get_keys ], [ "key2", "key3" ] ); |
|
114
|
3
|
|
|
3
|
|
1308
|
} |
|
|
3
|
|
|
|
|
10
|
|
|
|
3
|
|
|
|
|
13
|
|
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |