The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Tie::Hash::Expire - Hashes with keys that expire after a user-set period.

SYNOPSIS

  use Tie::Hash::Expire;

  my %test;
  tie %test, 'Tie::Hash::Expire', {'expire_seconds' => 10};

  $test{'dog'} = 'doghouse';
  sleep 5;
  $test{'bird'} = 'nest';
  sleep 5;

  print keys %test, "\n";       # The only key is 'bird'

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.

No finer resolution is currently available than seconds. The number of seconds specified by 'expire_seconds' is taken to mean an absolute maximum lifespan for the key. In other words, if you set 'expire_seconds' to 1 second, 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.