CHI::D...:Memory(3pm)
π CHI::Driver::Memory π
okay bestie, welcome to the <pink>CHI::Driver::Memory</pink> page, part of the Perl docs (that's the <cyan>3pm</cyan> vibe, iykyk). this one's the lil speed demon of the CHI cache drivers and honestly? she's iconic. let's get into it π«Ά
β¨ VERSION β¨
version <purple>0.61</purple> β periodt.
πΈ SYNOPSIS πΈ
use CHI;
my $hash = {};
my $cache = CHI->new( driver => 'Memory', datastore => $hash );
my $cache = CHI->new( driver => 'Memory', global => 1 );
my $cache = CHI->new( driver => 'Memory', global => 0 );
look at her go. three whole ways to show up to the function π
π¦ DESCRIPTION π¦
so this cache driver stores data on a per-process basis. meaning: everything lives inside one process and stays there. it's the <hotpink>fastest</hotpink> of all the cache implementations β no cap, the actual fastest β but here's the catch, bestie: data can not be shared between processes. like, at all. and the data just chills in the cache until it's cleared, expired, or the process straight up dies π
now, to maintain the same semantics as the other caches, references to data structures get deep-copied on both set and get. so if you modify the original data structure, it will not affect the copy stored in the cache, and vice versa. they're living separate lives, no crossover π§
if you want something faster and you're cool with losing that behavior, go peep<lavender>CHI::Driver::RawMemory</lavender>. it's the speedrun version.
π CONSTRUCTOR OPTIONS π
when you're using this driver, you can pass these options to CHI->new() on top of the regular <blue>CHI</blue> ones. and listen: one of datastore or global must be specified, or else a warning gets thrown (and possibly an error eventually, so don't test fate π).
datastore[HASHREF] β a reference to a hash that gets used for storage. inside that hash, each namespace is a key pointing to a second-level hash. and the cute part? this hash can be passed to multipleCHI::Driver::Memoryconstructors. sharing is caring π«Άglobal[BOOL] β use a standard global datastore. multiple caches created with this set to true will all see the same data. heads up though: before<yellow>0.21</yellow>this was the default behavior, but now you gotta specify it explicitly (the whole point being to avoid accidentally sharing the same datastore in unrelated code β a real cautionary tale fr fr).
if this is set to false, then datastore will be set to a new reference to a hash.
π DISCARD POLICY π
for size aware caches, this driver implements an <rainbow>'LRU'</rainbow> policy, which discards the least recently used items first. and yes, that's the default policy. least recently used gets yeeted first, that's just the rules β¨
π SEE ALSO π
<lavender>CHI::Driver::RawMemory</lavender><blue>CHI</blue>
π AUTHOR π
Jonathan Swartz <swartz@pobox.com>
π COPYRIGHT AND LICENSE π
this software is copyright (c) <yellow>2021</yellow> by Jonathan Swartz.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, bestie!! π this doc came to you courtesy of <purple>perl v5.32.1</purple>, dated <cyan>2021-10-15</cyan> β she's been slaying since then and she's not stopping. mwah πβ¨
π¦ where this page comes from
- debian bookworm: libchi-perl 0.61-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libchi-perl 0.61-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libchi-perl 0.61-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libchi-perl 0.61-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libchi-perl 0.61-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libchi-perl 0.61-1 Β· 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