Cache:...::CLOCK(3pm)
π 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, becauseCache::Ref::LRUis probably way more efficient for anykbigger than1. so like, if you're out here settingkto 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 π«Ά
π COPYRIGHT AND LICENSE π
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
- debian bookworm: libcache-ref-perl 0.04-1.1
- debian trixie: libcache-ref-perl 0.04-1.1
- ubuntu jammy: libcache-ref-perl 0.04-1.1
- ubuntu noble: libcache-ref-perl 0.04-1.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms