3 # Tests Koha::Cache and whichever type of cache is enabled (through Koha::Cache)
8 use Test::More tests => 9;
11 use_ok('Koha::Cache');
12 use_ok('C4::Context');
16 my $cache = Koha::Cache->new ();
18 skip "Cache not enabled", 7 unless (Koha::Cache->is_cache_active() && defined $cache);
20 # test fetching an item that isnt in the cache
21 is( $cache->get_from_cache("not in here"), undef, "fetching item NOT in cache");
23 # test expiry time in cache
24 $cache->set_in_cache("timeout", "I AM DATA", 1); # expiry time of 1 second
26 is( $cache->get_from_cache("timeout"), undef, "fetching expired item from cache");
28 # test fetching a valid, non expired, item from cache
29 $cache->set_in_cache("clear_me", "I AM MORE DATA", 1000); # overly large expiry time, clear below
30 $cache->set_in_cache("dont_clear_me", "I AM MORE DATA22", 1000); # overly large expiry time, clear below
31 is( $cache->get_from_cache("clear_me"), "I AM MORE DATA", "fetching valid item from cache");
33 # test clearing from cache
34 $cache->clear_from_cache("clear_me");
35 is( $cache->get_from_cache("clear_me"), undef, "fetching cleared item from cache");
36 is( $cache->get_from_cache("dont_clear_me"), "I AM MORE DATA22", "fetching valid item from cache (after clearing another item)");
38 #test flushing from cache
39 $cache->set_in_cache("flush_me", "testing 1 data");
41 is( $cache->get_from_cache("flush_me"), undef, "fetching flushed item from cache");
42 is( $cache->get_from_cache("dont_clear_me"), undef, "fetching flushed item from cache");