<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I’ve created a new Erlang cache library, from the lessons and needs we had in MongooseIM, called segmented_cache, code available at <a href="https://github.com/esl/segmented_cache" class="">https://github.com/esl/segmented_cache</a> and hex package here <a href="https://hex.pm/packages/segmented_cache" class="">https://hex.pm/packages/segmented_cache</a>, and I’m looking for opinions, thoughts, kudos, or maybe even contributions :)<div class=""><div class=""><br class=""></div><div class=""><div class="">1. How does it work: it uses a coarse-grained strategy, that is, it keeps a set of ETS tables that are periodically rotated, and on rotation, the last table is cleared.</div><div class=""><br class=""></div><div class="">2. What is different from all other cache libraries I saw:</div><div class="">* Time-to-live: entries are inserted in buckets (ets tables) that are entirely dropped when their ttl is triggered, making ttls very coarsed-grained, and book-keeping extremely simple and performant.</div><div class="">* Extensible values: we can configure a callback to merge old and new values upon key insert conflict, like, if values are maps, we can use maps:merge/2.</div><div class="">* Concurrency: this implementation is specially tailored for massively concurrent cache lookups and inserts: many caches in Erlang read from an ets table with read_concurrency but serialise inserts through a gen_server, which, in high insert bursts, becomes a bottleneck, not considering duplicates inserts that infinitely many workers might request. Other caches serialise read and writes through a gen_server that keeps the data in a map in its state: this is not only a bottleneck but a source of garbage, as the map is copied on every mutation. Here instead, the cache uses a –bunch of– ets table with read_concurrency, write_concurrency, and decentralized_counters, to maximise concurrent throughput of all read and writes. It also stores references to the buckets, the index, and the merge strategy, using persistent_term, to maximise performance.</div><div class="">* Instrumentation: lookups raise telemetry events with metadata about cache hits or misses, and the duration of the lookup operation, aiding at following the RED method.</div></div></div><div class=""><br class=""></div><div class="">Hope somebody finds it useful, and I get some feedback on the idea :)</div><div class="">Nelson.</div></body></html>
<br>
<div><b><span style="font-size:10.0pt;font-family:"Arial",sans-serif"><br></span></b></div><div><b><span style="font-size:10.0pt;font-family:"Arial",sans-serif">Our
upcoming conferences: </span></b><span style="font-family:"Times New Roman",serif"></span></div><span style="font-size:10.0pt;font-family:"Times New Roman",serif"></span><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:black"></span><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:black"></span><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:black"></span><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:black"></span><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:black"></span><br><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:black"></span><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:black"></span><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:black"><a href="https://www2.elixirconf.eu/elixir-conf-2021/es" target="_blank"><span style="color:black">ElixirConf EU:</span></a> 8-10 September
2021</span><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:black"></span><br><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:black"></span><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:black"></span><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:black"><a href="https://www2.codesync.global/code-beam-sf-2021/es" target="_blank"><span style="color:black">Code Beam SF:</span></a> 4-5 November
2021</span><span style="font-family:"Times New Roman",serif;color:black"></span>

<div><br></div>

<p><span style="font-size:7.5pt;font-family:"Arial",sans-serif;color:black">Erlang Solutions cares about your data and privacy;
please find all details about the basis for communicating with you and the way we
process your data in our <a href="https://www.erlang-solutions.com/privacy-policy.html" target="_blank"><span style="color:black">Privacy Policy</span></a>. You can
update your email preferences or opt-out from receiving Marketing emails <a href="https://www2.erlang-solutions.com/email-preference?epc_hash=JtO6C7Q2rJwCdZxBx3Ad8jI2D4TJum7XcUWcgfjZ8YY" target="_blank"><span style="color:black">here</span></a>.</span><span style="font-size:15.5pt;font-family:"Times New Roman",serif;color:black"></span></p>





<p dir="ltr" style="font-size:1.3em;line-height:1.656;margin-top:0pt;margin-bottom:0pt"><font face="Arial"></font></p>