CHI::D...:Memory(3pm)

πŸ“¦
version 0.61 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 multiple CHI::Driver::Memory constructors. 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>


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