line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CHI::t::Driver::Memory; |
2
|
|
|
|
|
|
|
$CHI::t::Driver::Memory::VERSION = '0.60'; |
3
|
3
|
|
|
3
|
|
570
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
119
|
|
4
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
89
|
|
5
|
3
|
|
|
3
|
|
488
|
use CHI::Test; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
22
|
|
6
|
3
|
|
|
3
|
|
1290
|
use CHI::Test::Driver::Role::CheckKeyValidity; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
73
|
|
7
|
3
|
|
|
3
|
|
1542
|
use Test::Warn; |
|
3
|
|
|
|
|
5188
|
|
|
3
|
|
|
|
|
196
|
|
8
|
3
|
|
|
3
|
|
19
|
use base qw(CHI::t::Driver); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1919
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Skip multiple process test |
11
|
3
|
|
|
3
|
0
|
507
|
sub test_multiple_processes { } |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new_cache_options { |
14
|
276
|
|
|
276
|
0
|
424
|
my $self = shift; |
15
|
|
|
|
|
|
|
|
16
|
276
|
|
|
|
|
1278
|
return ( $self->SUPER::new_cache_options(), global => 1 ); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new_cache { |
20
|
182
|
|
|
182
|
0
|
323
|
my $self = shift; |
21
|
|
|
|
|
|
|
|
22
|
182
|
|
|
|
|
616
|
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
|
|
|
|
611
|
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
|
|
|
|
|
481
|
$params{roles} = ['+CHI::Test::Driver::Role::CheckKeyValidity']; |
33
|
182
|
|
|
|
|
307
|
$params{test_object} = $self; |
34
|
|
|
|
|
|
|
|
35
|
182
|
|
|
|
|
1029
|
my $cache = CHI->new(%params); |
36
|
182
|
|
|
|
|
880
|
return $cache; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub test_short_driver_name : Tests { |
40
|
1
|
|
|
1
|
0
|
150
|
my ($self) = @_; |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
2
|
my $cache = $self->{cache}; |
43
|
1
|
|
|
|
|
31
|
is( $cache->short_driver_name, 'Memory' ); |
44
|
3
|
|
|
3
|
|
68
|
} |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
16
|
|
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
|
619
|
my ( $cache, $cache2 ); |
50
|
3
|
|
|
3
|
|
175
|
warning_like( sub { $cache = CHI->new( driver => 'Memory' ) }, |
51
|
3
|
|
|
|
|
45
|
qr/must specify either/ ); |
52
|
3
|
|
|
3
|
|
135
|
warning_like( sub { $cache2 = CHI->new( driver => 'Memory' ) }, |
53
|
3
|
|
|
|
|
2080
|
qr/must specify either/ ); |
54
|
3
|
|
|
|
|
1898
|
$cache->set( 'foo', 5 ); |
55
|
3
|
|
|
|
|
44
|
is( $cache2->get('foo'), 5, "defaulted to global datastore" ); |
56
|
3
|
|
|
3
|
|
1027
|
} |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
16
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Make sure two caches don't share datastore |
59
|
|
|
|
|
|
|
# |
60
|
|
|
|
|
|
|
sub test_different_datastores : Tests { |
61
|
3
|
|
|
3
|
0
|
593
|
my $self = shift; |
62
|
3
|
|
|
|
|
19
|
my $cache1 = CHI->new( driver => 'Memory', datastore => {} ); |
63
|
3
|
|
|
|
|
21
|
my $cache2 = CHI->new( driver => 'Memory', datastore => {} ); |
64
|
3
|
|
|
|
|
45
|
$self->set_some_keys($cache1); |
65
|
3
|
|
|
|
|
49
|
ok( !$cache2->get_keys() ); |
66
|
3
|
|
|
3
|
|
793
|
} |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
10
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Make sure two global=0 caches don't share datastore |
69
|
|
|
|
|
|
|
# |
70
|
|
|
|
|
|
|
sub test_different_global_0 : Tests { |
71
|
3
|
|
|
3
|
0
|
470
|
my $self = shift; |
72
|
3
|
|
|
|
|
20
|
my $cache1 = CHI->new( driver => 'Memory', global => 0 ); |
73
|
3
|
|
|
|
|
15
|
my $cache2 = CHI->new( driver => 'Memory', global => 0 ); |
74
|
3
|
|
|
|
|
32
|
$self->set_some_keys($cache1); |
75
|
3
|
|
|
|
|
32
|
ok( !$cache2->get_keys() ); |
76
|
3
|
|
|
3
|
|
785
|
} |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
11
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Make sure cache is cleared when datastore itself is cleared |
79
|
|
|
|
|
|
|
# |
80
|
|
|
|
|
|
|
sub test_clear_datastore : Tests { |
81
|
3
|
|
|
3
|
0
|
485
|
my $self = shift; |
82
|
3
|
|
|
|
|
46
|
$self->num_tests( $self->{key_count} * 3 + 6 ); |
83
|
|
|
|
|
|
|
|
84
|
3
|
|
|
|
|
299
|
my (@caches); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my %datastore; |
87
|
3
|
|
|
|
|
16
|
$caches[0] = |
88
|
|
|
|
|
|
|
$self->new_cache( namespace => 'name', datastore => \%datastore ); |
89
|
3
|
|
|
|
|
15
|
$caches[1] = |
90
|
|
|
|
|
|
|
$self->new_cache( namespace => 'other', datastore => \%datastore ); |
91
|
3
|
|
|
|
|
14
|
$caches[2] = |
92
|
|
|
|
|
|
|
$self->new_cache( namespace => 'name', datastore => \%datastore ); |
93
|
3
|
|
|
|
|
95
|
$self->set_some_keys( $caches[0] ); |
94
|
3
|
|
|
|
|
18
|
$self->set_some_keys( $caches[1] ); |
95
|
3
|
|
|
|
|
62
|
%datastore = (); |
96
|
|
|
|
|
|
|
|
97
|
3
|
|
|
|
|
13
|
foreach my $i ( 0 .. 2 ) { |
98
|
9
|
|
|
|
|
101
|
$self->_verify_cache_is_cleared( $caches[$i], |
99
|
|
|
|
|
|
|
"cache $i after out of scope" ); |
100
|
|
|
|
|
|
|
} |
101
|
3
|
|
|
3
|
|
1013
|
} |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
14
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub test_lru_discard : Tests { |
104
|
2
|
|
|
2
|
0
|
350
|
my $self = shift; |
105
|
2
|
50
|
|
|
|
11
|
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
|
|
937
|
} |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
17
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |