1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
use strict;
use warnings;
use Test::More;
use File::Temp qw(tempdir);
use Carp;
$SIG{__DIE__} = sub { confess @_ };
BEGIN { plan tests => 7 }
use_ok('Cache::File');
my $tempdir = tempdir(CLEANUP => 1);
my %hash;
my $cache = tie %hash, 'Cache::File', { cache_root => $tempdir };
my $key = 'testkey';
$hash{$key} = 'test data';
ok($cache->exists($key), 'store worked');
is($hash{$key}, 'test data', 'fetch worked');
delete $hash{$key};
ok(!$cache->exists($key), 'delete worked');
{
sub load_func {
return "You requested ".$_[0]->key();
}
my %hash;
my $cache = tie %hash, 'Cache::File',
{ cache_root => $tempdir, load_callback => \&load_func };
my $key = 'testkey';
ok(!$cache->exists($key), 'key doesnt exist');
is($hash{$key}, "You requested $key", 'load worked');
delete $hash{$key};
ok(!$cache->exists($key), 'delete worked');
}
|