Cache:...::CLOCK(3pm)

πŸ“¦
version 0.04 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble

πŸ’– Cache::Ref::CLOCK β€” the manual, but make it cute πŸ’–

okay bestie, pull up a chair, we're doing the Cache::Ref::CLOCK page (that's the CLOCK cache replacement algorithm, for the record) and it's genuinely so good. it lives in the 3pm manual, perl's user-contributed docs corner, and i'm about to make it make sense 🫢


✨ SYNOPSIS ✨

so here's the vibe, right at the top:

my $c = Cache::Ref::CLOCK->new(
    size => $n,
    k    => $k,
);

that's literally it. that's the whole entrance. slay πŸ’…


🌸 DESCRIPTION 🌸

okay so. this algorithm gives you a second chance FIFO cache expiry policy, and it does it using a circular buffer. that's the whole trick. a circle. a little ring of vibes. β­•

it's a very well accepted page replacement algorithm β€” like, famously accepted, iconic, respected in the field β€” but the reasons everyone loves it are largely irrelevant in this context. why? because cache hits don't need to be serialized in a multiprocessing context, since they only require an idempotent operation (setting a bit to 1). so like, all that fame? not really about us. we're just here for the circular buffer energy. it's giving "borrowed the algorithm, left the baggage at home" ✨


πŸŽ€ ATTRIBUTES πŸŽ€

size

the size of the live entries. that's it, that's the attribute. how many things are actually alive in there πŸ’–

k

okay this one has lore. k is the initial value given to all hit entries β€” every entry that gets hit starts its life with this number, bestie.

then, as the hand moves through the circular buffer, it decrements the counters. the hand just walks around the circle being like "okay, minus one for you, minus one for you" πŸ™ˆ

the default is 1, which gives you semantics similar to a second chance FIFO cache. classic. cozy. exactly what you expect.

larger values of k model LRU more accurately. more accurate! sounds great! butβ€”

this is pretty silly though, because Cache::Ref::LRU is probably way more efficient for any k bigger than 1. so like, if you're out here setting k to 5, maybe just go use the LRU one instead? no cap. i'm not being mean, i'm being helpful πŸ’€

πŸ‘‘ AUTHOR πŸ‘‘

Yuval Kogman. the icon. the legend. the main character of this manpage 🫢


this software is copyright (c) 2010 by Yuval Kogman.

it's free software β€” you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. so go forth, remix, redistribute, be free my love πŸ¦‹


and that's the whole page, fr fr. this was rendered from perl v5.32.0, dated 2021-01-07, and it's the Cache:...::CLOCK(3pm) page πŸ’œ ty for reading, go build something with a circular buffer in it, mwah πŸŽ€βœ¨

πŸ“¦ where this page comes from