BEGIN { plan
tests
=> 15 };
ok(1);
%data
= (0..501);
tie
%cache
, Tie::Hash::Cache::MRU,
SIZE
=> 5,
HASH
=> \
%data
;
tie
%cache2
, Tie::Hash::Cache::MRU,
SIZE
=> 5,
LIFE
=> 3,
HASH
=> \
%data
;
ok(
$cache
{28} ==
$data
{28});
ok(
$cache
{38} ==
$data
{38});
ok(
$cache
{48} ==
$data
{48});
ok(
$cache
{58} ==
$data
{58});
ok(
$cache
{68} ==
$data
{68});
ok(
$cache
{78} ==
$data
{78});
ok(
$cache
{88} ==
$data
{88});
ok(
$cache
{98} ==
$data
{98});
ok(
$cache
{24} ==
$data
{24});
ok(
$cache
{22} ==
$data
{22});
$data
{22} =
'football'
;
ok(
$cache
{22} ne
$data
{22});
sub
CURRENT(){0};
sub
OLD(){1};
sub
TIME(){2}
sub
SIZE(){3};
sub
LIFE(){4};
sub
HASH(){5};
sub
S(){6};
sub
F(){7};
sub
D(){8};
sub
E(){9};
sub
C(){10};
sub
FK(){11};
sub
NK(){12};
sub
DE(){13};
ok(
$cache2
{28} ==
$data
{28});
print
STDERR
"cache2 TIME: @{[%{tied(%cache2)->[TIME]}]}\n"
;
print
STDERR
"cache2 CURRENT: @{[%{tied(%cache2)->[CURRENT]}]}\n"
;
print
STDERR
"cache2 OLD: @{[%{tied(%cache2)->[OLD]}]}\n"
;
$data
{28} =
'hockey'
;
ok(
$cache2
{28} ne
$data
{28});
print
STDERR
"sleeping 5\n"
;
sleep
5;
ok(
$cache2
{28} eq
$data
{28});
print
STDERR
"cache2 TIME: @{[%{tied(%cache2)->[TIME]}]}\n"
;
print
STDERR
"cache2 CURRENT: @{[%{tied(%cache2)->[CURRENT]}]}\n"
;
print
STDERR
"cache2 OLD: @{[%{tied(%cache2)->[OLD]}]}\n"
;