NAME
Tie::Hash::Expire - Hashes with keys that expire after a user-set period.
SYNOPSIS
my
%test
;
tie
%test
,
'Tie::Hash::Expire'
, {
'expire_seconds'
=> 10};
$test
{
'dog'
} =
'doghouse'
;
sleep
5;
$test
{
'bird'
} =
'nest'
;
sleep
6;
keys
%test
,
"\n"
;
# The only key is 'bird'
my
%hi_res
;
tie
%hi_res
,
'Tie::Hash::Expire'
, {
'expire_seconds'
=> 5.21};
# Decimal number of seconds works if you have Time::HiRes
ABSTRACT
Hashes tied to Tie::Hash::Expire have keys that cease to exist 'expire_seconds' after their most recent modification or their creation.
DESCRIPTION
Hashes tied to Tie::Hash::Expire behave like normal hashes in all respects except that when a key is added or the value associated with a key is changed, the current time is stored, and after 'expire_seconds' the key and value are removed from the hash.
Resolutions finer than seconds are available if the module finds access to Time::HiRes. If Time::HiRes is available, you can expect expiration to be accurate to 0.001 seconds. You may specify 'expire_seconds' to be decimal numbers like 5.12 . If Time::HiRes is available, this number will be used precisely. If you specify a decimal number and don't have access to Time::HiRes, a warning is generated and the code will function as though you specified the next higher integer.
The number of seconds specified by 'expire_seconds' is taken to mean an absolute maximum lifespan for the key, at the resolution described above. In other words, if you set 'expire_seconds' to 1 second, and do not have Time::HiRes, keys could expire as quickly as the next machine instruction, but will not last longer than 1 second.
AUTHOR
Jeff Yoak, <jeff@yoak.com>
COPYRIGHT AND LICENSE
Copyright 2004 by Jeff Yoak
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.