Expire(3pm)

πŸ“¦
version 0.03 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

Tie::Hash::Expire β€” bestie, it's hashes, but the keys expire after a period you set yourself πŸ’…

So okay, this is the manpage for Expire(3pm), aka the Perl module Tie::Hash::Expire. Sit down, grab a boba, we're tying hashes. πŸ§‹


πŸ’– SYNOPSIS πŸ’–

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

See how dog just… left the chat? πŸ•πŸ’¨ Yeah. That's the whole vibe.


πŸ¦‹ ABSTRACT πŸ¦‹

Hashes that are tied to Tie::Hash::Expire have keys that cease to exist 'expire_seconds' after their most recent modification, or after their creation. That's it, that's the abstract, short and slay. πŸŽ€


🌸 DESCRIPTION 🌸

Hashes tied to Tie::Hash::Expire behave like normal hashes in all respects, no cap β€” except for one lil thing: when a key gets added, or when the value associated with a key gets changed, the current time gets stored. Then after 'expire_seconds' have passed, the key and its value get removed from the hash. Gone. Evicted. Blocked. πŸ’€

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, that number will be used precisely. If you specify a decimal number and you don't have access to Time::HiRes, a warning is generated and the code will function as though you specified the next higher integer. (So 5.12 lowkey becomes 6. Rude, but okay.) 😭

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 you don't have Time::HiRes, keys could expire as quickly as the next machine instruction, but they will not last longer than 1 second. It's giving "may leave early, will never overstay." ✨


πŸ‘‘ AUTHOR πŸ‘‘

Jeff Yoak, <jeff@yoak.com> β€” the icon who built this. Periodt.


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.


πŸ’œ Seriously though, if you're redistributing this, keep that copyright notice and the "same terms as Perl itself" line intact β€” that's the whole legal vibe, don't let it expire on you.

And that's a wrap, bestie! 🫢 This page came to you from perl v5.36.0, dated 2022-10-13, and it lives in the Expire(3pm) slot of the manual. Go forth and let your keys expire on schedule, the way nature β€” and Jeff β€” intended. 🌈🌟

πŸ“¦ where this page comes from