Tie::Hash::Expire(3pm)

Tie::Hash::Expire3pm

Hashes with keys that expire after a user-set period.

Usage

  use Tie::Hash::Expire;
  my %test;
  tie %test, 'Tie::Hash::Expire', {'expire_seconds' => 10};
  $test{'dog'} = 'doghouse';
  sleep 5;
  $test{'bird'} = 'nest';
  sleep 6;
  print 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.

Overview

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.

Releases

5 releases since Debian 9 (Stretch); the text changed 2 times.

  1. 9–10
  2. 11
  3. 12–13

Author

Jeff Yoak, <[email protected]>

From libtie-hash-expire-perl 0.03-3 in Debian 13 (Trixie). Parsed by carta from the page's man source.