Jifty:...mcached(3pm)
π Jifty::DBI::Record::Memcached β bestie edition π
okay so this is a page from the User Contributed Perl Documentation collection, and it's genuinely one of my faves because it's just... vibes + caching. no drama. let's go π¦
β¨ NAME β¨
Jifty::DBI::Record::Memcached β records with caching behavior. yes queen, that's the whole thing, records that remember themselves for a lil bit π
β¨ SYNOPSIS β¨
bestie, you just inherit from it and you're done:
package Myrecord;
use base qw/Jifty::DBI::Record::Memcached/;
that's it. that's the whole setup. iconic behavior honestly π
β¨ DESCRIPTION β¨
so this module subclasses the main Jifty::DBI::Record package to add a caching layer on top. lowkey genius.
the public interface stays exactly the same, no cap β the only glow-up is that records which have been loaded in the last few seconds may get reused by subsequent get or load methods without retrieving them from the database. so like, the database gets a break, and we love that for it πΈ
β¨ METHODS β¨
π load_from_hash
Overrides the implementation from Jifty::DBI::Record to add support for caching. that's the assignment, and it ate π₯
π load_by_cols
Overrides the implementation from Jifty::DBI::Record to add support for caching. same energy, same job, periodt π
π _cache_config
you can override this method to change the duration of the caching from the default of 5 seconds. five seconds! that's like, one (1) TikTok, basically.
for example, to cache records for up to 30 seconds, add the following method to your class:
sub _cache_config {
{ 'cache_for_sec' => 30 }
}
π memcached_config
returns a hash containing arguments to pass to Cache::Memcached during construction. the defaults are like:
(
services => [ '127.0.0.1:11211' ],
debug => 0,
)
you may want to override this method if you want a customized cache configuration:
sub memcached_config {
(
servers => [ '10.0.0.15:11211', '10.0.0.15:11212',
'10.0.0.17:11211', [ '10.0.0.17:11211', 3 ] ],
debug => 0,
compress_threshold => 10_000,
);
}
like look at that. multiple servers. a weighted one. compression threshold at 10_000. main character energy fr fr π
π cache_key_prefix
returns the prefix we should prepend to all cache keys. and ngl this one is important:
if you're using one memcached for multiple applications, you want this to be different for each application or they might end up mingling data. π
mingling data!! the horror!! give each app its own prefix bestie, don't let them share a toothbrush π
β¨ AUTHOR β¨
Matt Knopp <mhat@netlag.com> β thank you king, we appreciate you π«Ά
β¨ SEE ALSO β¨
Jifty::DBIJifty::DBI::Record
go read those too, they're the parents and they're slaying in their own way β
and that's the whole page, bestie!! π this one shipped as part of perl v5.34.0, dated 2022-06-15, and it's filed under Jifty:...mcached(3pm) in the User Contributed Perl Documentation. mwah. go cache something responsibly ππ§π
π¦ where this page comes from
- debian bookworm: libjifty-dbi-perl 0.78-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libjifty-dbi-perl 0.78-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libjifty-dbi-perl 0.78-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libjifty-dbi-perl 0.78-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libjifty-dbi-perl 0.78-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms