Cache:...yCache(3pm)

πŸ’– Cache::SharedMemoryCache πŸ’–

okay so bestie, welcome to the perl docs, User Contributed Perl Documentation edition, and we're talking about Cache::SharedMemoryCache today πŸŽ€


✨ NAME ✨

Cache::SharedMemoryCache β€” it extends the MemoryCache. that's the whole name, short and iconic, we love a concise queen πŸ’…


🌸 DESCRIPTION 🌸

so here's the tea: SharedMemoryCache extends the MemoryCache class and binds the data store to shared memory so that separate processes can use the same cache. literally the whole point β€” multiple processes, one cache, sharing is caring 🫢

but ngl, the official recommendation now is to use FileCache instead of SharedMemoryCache. not me being the bearer of bad news 😭 here's why:

  1. FileCache provides equal or better performance in all cases that we've been able to test. this is due to all modern OS's ability to buffer and cache file system accesses very well β€” like, they're genuinely so good at it ✨
  2. FileCache has no real limits on cached object size or the number of cached objects, whereas SharedMemoryCache has limits, and rather low ones at that πŸ’€ not the low limits bestie
  3. FileCache works well on every OS, whereas SharedMemoryCache works only on systems that support IPC::ShareLite. and IPC::ShareLite is an impressive effort β€” but think about how hard it is to get shared memory working properly on one system. now imagine writing a wrapper around shared memory for many operating systems. yeah. exactly. the audacity of that task is enormous πŸ™ˆ

🌈 SYNOPSIS 🌈

here's the vibe, copy-paste ready, no cap:

use Cache::SharedMemoryCache;

my %cache_options_= ( 'namespace' => 'MyNamespace',
                      'default_expires_in' => 600 );

my $shared_memory_cache =
  new Cache::SharedMemoryCache( \%cache_options ) or
    croak( "Couldn't instantiate SharedMemoryCache" );

look at that. 'namespace' set to 'MyNamespace', 'default_expires_in' set to 600, and if the constructor flops we croak with "Couldn't instantiate SharedMemoryCache" β€” dramatic and correct πŸ’…


πŸ¦‹ METHODS πŸ¦‹

see Cache::Cache for the API documentation. that's where the actual method lore lives, iykyk πŸ‘‘


πŸŽ€ OPTIONS πŸŽ€

see Cache::Cache for the standard options. all the standard ones, over there, go look 🌸


πŸ’œ PROPERTIES πŸ’œ

see Cache::Cache for the default properties. yeah. also over there 🧚


⭐ SEE ALSO ⭐

  • Cache::Cache
  • Cache::MemoryCache

πŸ‘‘ AUTHOR πŸ‘‘

  • original author: DeWitt Clinton <dewitt@unto.net>
  • last author: $Author: dclinton $
  • copyright (C) 2001-2003 DeWitt Clinton

okay and that's a wrap on this one 🫢 this page is from perl v5.34.0, dated 2022-06-30, and it's part of the User Contributed Perl Documentation besties. go forth and maybe use FileCache instead, fr fr πŸ’–βœ¨

πŸ“¦ where this page comes from