Mojo::Cache(3)
β¨ Mojo::Cache β¨
Okay bestie, so this is a Perl module β it lives over in the User Contributed Perl Documentation section of the manual, and honestly? It's kind of a vibe. Let's get into it π
π NAME π
Mojo::Cache β a naive in-memory cache. Yes, "naive" is literally in the name, she's honest about it, we respect that π«Ά
π¦ SYNOPSIS π¦
Here's the whole flex, copy it exactly or it won't work, iykyk:
use Mojo::Cache;
my $cache = Mojo::Cache->new(max_keys => 50);
$cache->set(foo => 'bar');
my $foo = $cache->get('foo');
Literally three lines and you're caching. Obsessed πΈ
π DESCRIPTION π
So Mojo::Cache is a naive in-memory cache β it keeps stuff in memory so you don't gotta re-do the work β and it comes with size limits so it doesn't just eat all your RAM like some kind of chaos demon π It's simple, it's small, it slays.
β ATTRIBUTES β
Mojo::Cache implements these following attributes, no cap:
π max_keys
my $max = $cache->max_keys;
$cache = $cache->max_keys(50);
This is the maximum number of cache keys, and it defaults to 100 β that's the number, that's the default, don't forget it π
β οΈ Heads up bestie: setting the value to0will disable caching. Like, entirely. Zero keys allowed. She's off duty π So don't set it to0and then act surprised, fr fr.
π METHODS π
Mojo::Cache inherits all methods from Mojo::Base and implements these following new ones π
π§ get
my $value = $cache->get('foo');
Gets you the cached value. That's it. That's the whole method. Iconic brevity π
π₯ set
$cache = $cache->set(foo => 'bar');
Sets the cached value. Also returns the cache back to you so you can chain, main character energy β¨
π SEE ALSO π
Go be nosy, these are all iconic:
MojoliciousMojolicious::Guides- <https://mojolicious.org>
And that's the page! π This lil beauty is from perl v5.42.0 and dated 2026-07-15 β so go forth, cache things, keep max_keys off 0, and slay the day, bestie π¦π
π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Mojolicious 9.480.0-bp160.2.1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms