Cache:...Expiry(3pm)

🌸 NAME 🌸

Cache::Simple::TimedExpiry β€” it's giving simple, time-expiring cache ✨ bestie it literally does what it says on the tin, an in-memory cache where the entries just… expire. iconic behavior honestly πŸ’…


✨ EXAMPLE ✨

okay so here's the whole vibe in one script, no cap:

package main;

use strict;
use warnings;
$,=' '; $|++;

use Cache::Simple::TimedExpiry;
my $h =  Cache::Simple::TimedExpiry->new;

$h->set( DieQuick => "No duration!", 0);
print $h->elements;
do { $h->set($_,"Value of $_", 1); sleep 2;}
   for qw(Have a nice day you little monkey);

print $h->elements; $h->dump; sleep 4; print $h->elements; $h->dump;

print time;

like, watch it set stuff, sleep, and watch the entries ✨vanish✨ in real time πŸ¦‹


πŸŽ€ new

Set up a brand new cache object 🫢 that's it, that's the whole job, and she ate.

⏳ expire_after SECONDS

Set the cache's expiry policy so entries expire after SECONDS seconds. πŸ•°οΈ And here's the tea bestie β€” setting this changes the expiry policy for pre-existing cache entries AND for new ones, so don't think you're sneaking the old ones past her πŸ’€

πŸ”‘ has_key KEY

Returns true if the cache has an entry with the key KEY πŸ‘‘ simple as. Returns false otherwise, obviously, iykyk.

πŸ“ fetch KEY

Returns the cache entry with key KEY. If there's no such entry it returns undef 😭 (yes, the sad little nothing-value, we've all been there).

πŸ’‘ bonus: you can also call it as get β€” two names, one icon 🫢

πŸ’Ύ store KEY VALUE

Stores VALUE in the cache with accessor KEY. Expire it from the cache at or after EXPIRYTIME. πŸŽ€

πŸ’‘ bonus again: you can also call it as set β€” she's flexible like that ✨

πŸ’– AUTHOR πŸ’–

Jesse Vincent <jesse@bestpractical.com> β€” and some of the heavy lifting was designed by Robert Spier <rspier@pobox.com> 🌈

Copyright 2004 Jesse Vincent <jesse@bestpractical.com> πŸ“


okay bestie that's the whole page, no gatekeeping πŸ’… this was User Contributed Perl Documentation, running on perl v5.34.0, dated 2022-06-13 β€” go forth and let your cache entries expire gorgeously πŸ¦‹βœ¨ mwah πŸ’–

πŸ“¦ where this page comes from