| 1 | package CHI::t::Driver::RawMemory; | ||||||||||
| 2 | 1 | $CHI::t::Driver::RawMemory::VERSION = '0.60'; | |||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use CHI::Test; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use CHI::Test::Util qw(is_between); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use base qw(CHI::t::Driver::Memory); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | sub new_cache { | ||||||||||
| 10 | 85 | ▶ | my $self = shift; | ||||||||
|
Subroutine
new_cache: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 11 | |||||||||||
| 12 | 85 | my %params = ( $self->new_cache_options(), @_, ); | |||||||||
| 13 | |||||||||||
| 14 | # If new_cache called with datastore, ignore global flag (otherwise would be an error) | ||||||||||
| 15 | # | ||||||||||
| 16 | 85 | ▶ | if ( $params{datastore} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 3 | delete $params{global}; | |||||||||
| 18 | } | ||||||||||
| 19 | |||||||||||
| 20 | 85 | my $cache = CHI->new(%params); | |||||||||
| 21 | 85 | return $cache; | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | # Not applicable to raw memory | ||||||||||
| 25 | # | ||||||||||
| 26 | ▶ | sub test_deep_copy { } | |||||||||
|
Subroutine
test_deep_copy: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 27 | ▶ | sub test_scalar_return_values { } | |||||||||
|
Subroutine
test_scalar_return_values: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 28 | ▶ | sub test_serialize { } | |||||||||
|
Subroutine
test_serialize: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 29 | ▶ | sub test_serializers { } | |||||||||
|
Subroutine
test_serializers: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 30 | |||||||||||
| 31 | # Would need tweaking to pass | ||||||||||
| 32 | # | ||||||||||
| 33 | ▶ | sub test_append { } | |||||||||
|
Subroutine
test_append: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 34 | ▶ | sub test_compress_threshold { } | |||||||||
|
Subroutine
test_compress_threshold: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 35 | ▶ | sub test_custom_discard_policy { } | |||||||||
|
Subroutine
test_custom_discard_policy: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 36 | ▶ | sub test_lru_discard { } | |||||||||
|
Subroutine
test_lru_discard: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 37 | ▶ | sub test_size_awareness_with_subcaches { } | |||||||||
|
Subroutine
test_size_awareness_with_subcaches: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 38 | ▶ | sub test_stats { } | |||||||||
|
Subroutine
test_stats: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 39 | ▶ | sub test_subcache_overridable_params { } | |||||||||
|
Subroutine
test_subcache_overridable_params: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 40 | |||||||||||
| 41 | # Size of all items = 1 in this driver | ||||||||||
| 42 | # | ||||||||||
| 43 | sub test_size_awareness : Tests { | ||||||||||
| 44 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
test_size_awareness: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 45 | 1 | my ( $key, $value ) = $self->kvpair(); | |||||||||
| 46 | |||||||||||
| 47 | 1 | ok( !$self->new_cleared_cache()->is_size_aware(), | |||||||||
| 48 | "not size aware by default" ); | ||||||||||
| 49 | 1 | ok( $self->new_cleared_cache( is_size_aware => 1 )->is_size_aware(), | |||||||||
| 50 | "is_size_aware turns on size awareness" ); | ||||||||||
| 51 | 1 | ok( $self->new_cleared_cache( max_size => 10 )->is_size_aware(), | |||||||||
| 52 | "max_size turns on size awareness" ); | ||||||||||
| 53 | |||||||||||
| 54 | 1 | my $cache = $self->new_cleared_cache( is_size_aware => 1 ); | |||||||||
| 55 | 1 | is( $cache->get_size(), 0, "size is 0 for empty" ); | |||||||||
| 56 | 1 | $cache->set( $key, $value ); | |||||||||
| 57 | 1 | is( $cache->get_size, 1, "size is 1 with one value" ); | |||||||||
| 58 | 1 | $cache->set( $key, scalar( $value x 5 ) ); | |||||||||
| 59 | 1 | is( $cache->get_size, 1, "size is still 1 after override" ); | |||||||||
| 60 | 1 | $cache->set( $key, scalar( $value x 5 ) ); | |||||||||
| 61 | 1 | is( $cache->get_size, 1, "size is still 1 after same overwrite" ); | |||||||||
| 62 | 1 | $cache->set( $key, scalar( $value x 2 ) ); | |||||||||
| 63 | 1 | is( $cache->get_size, 1, "size is 1 after overwrite" ); | |||||||||
| 64 | 1 | $cache->set( $key . "2", $value ); | |||||||||
| 65 | 1 | is( $cache->get_size, 2, "size is 2 after second key" ); | |||||||||
| 66 | 1 | $cache->remove($key); | |||||||||
| 67 | 1 | is( $cache->get_size, 1, "size is 1 again after removing key" ); | |||||||||
| 68 | 1 | $cache->remove( $key . "2" ); | |||||||||
| 69 | 1 | is( $cache->get_size, 0, "size is 0 again after removing keys" ); | |||||||||
| 70 | 1 | $cache->set( $key, $value ); | |||||||||
| 71 | 1 | is( $cache->get_size, 1, "size is 1 with one value" ); | |||||||||
| 72 | 1 | $cache->clear(); | |||||||||
| 73 | 1 | is( $cache->get_size, 0, "size is 0 again after clear" ); | |||||||||
| 74 | |||||||||||
| 75 | 1 | my $time = time() + 10; | |||||||||
| 76 | 1 | $cache->set( $key, $value, { expires_at => $time } ); | |||||||||
| 77 | 1 | is( $cache->get_expires_at($key), | |||||||||
| 78 | $time, "set options respected by size aware cache" ); | ||||||||||
| 79 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 80 | |||||||||||
| 81 | sub test_max_size : Tests { | ||||||||||
| 82 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
test_max_size: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 83 | |||||||||||
| 84 | 1 | my $cache = $self->new_cleared_cache( max_size => 5 ); | |||||||||
| 85 | 1 | ok( $cache->is_size_aware, "is size aware when max_size specified" ); | |||||||||
| 86 | 1 | my $value = 'x'; | |||||||||
| 87 | |||||||||||
| 88 | 1 | ▶ | for ( my $i = 0 ; $i < 5 ; $i++ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | 5 | $cache->set( "key$i", $value ); | |||||||||
| 90 | } | ||||||||||
| 91 | 1 | ▶ | for ( my $i = 0 ; $i < 10 ; $i++ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | 10 | $cache->set( "key" . int( rand(10) ), $value ); | |||||||||
| 93 | 10 | is_between( $cache->get_size, 3, 5, | |||||||||
| 94 | "after iteration $i, size = " . $cache->get_size ); | ||||||||||
| 95 | 10 | is_between( scalar( $cache->get_keys ), | |||||||||
| 96 | 3, 5, "after iteration $i, keys = " . scalar( $cache->get_keys ) ); | ||||||||||
| 97 | } | ||||||||||
| 98 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 99 | |||||||||||
| 100 | # Test that we're caching a reference, not a deep copy | ||||||||||
| 101 | # | ||||||||||
| 102 | sub test_cache_ref : Tests { | ||||||||||
| 103 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
test_cache_ref: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 104 | 1 | my $cache = $self->{cache}; | |||||||||
| 105 | 1 | my $lst = ['foo']; | |||||||||
| 106 | 1 | $cache->set( 'key1' => $lst ); | |||||||||
| 107 | 1 | $cache->set( 'key2' => $lst ); | |||||||||
| 108 | 1 | is( $cache->get('key1'), $lst, "got same reference" ); | |||||||||
| 109 | 1 | is( $cache->get('key2'), $lst, "got same reference" ); | |||||||||
| 110 | 1 | $lst->[0] = 'bar'; | |||||||||
| 111 | 1 | is( $cache->get('key1')->[0], 'bar', "changed value in cache" ); | |||||||||
| 112 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 113 | |||||||||||
| 114 | sub test_short_driver_name : Tests { | ||||||||||
| 115 | 1 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
test_short_driver_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 116 | |||||||||||
| 117 | 1 | my $cache = $self->{cache}; | |||||||||
| 118 | 1 | is( $cache->short_driver_name, 'RawMemory' ); | |||||||||
| 119 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 120 | |||||||||||
| 121 | 1 | 1; | |||||||||