Stats for cache


I have used core.cache in some of my projects. It is a great library and I liked it a lot. It only lacks stats so I can adjust size of the cache based on some statistics. I have decided to write a custom cache implementation that would allow to get hit/miss stats for the cache. First it was a separate project but then I figured out that I need one change in core.cache itself which I can not hack nicely around. So here is the patch to add stats-aware cache implementation.

Quick demo:

What's new:

  • core.cache.stats namespace which provides MeasuredCache that implements CacheProtocol and a measured-cache function to instantiate it. MeasuredCache also implements MeasuredCacheProtocol which has only one responsibility - to return snapshot of hit/miss stats

  • core.cache.stats.counters namespace which provides a protocol (StatsCounterProtocol) that allows to implement hit/miss counters. There are two implementations already: one is based on long wrapped in atom, another one (which is used by default) is based on LongAdder

  • tests are there for all the methods that could be invoked

Caveats (in no particular order):

Things to finish before merge:

  • if you would like the idea I'll add more docs (maybe I should have started with this one so higher chances to be accepted?)

  • polish code (I'm not an expert in Clojure at all), naming and namespaces

Thank you in advance for the feedback




Sean Corfield
November 11, 2018, 8:21 PM

Still under consideration. I'm looking at a bunch of issues with this library and will include this as part of that with when I've figured out the other hard issues.

Oleksii Khomchenko
November 11, 2018, 7:26 PM

Good day. Any updates on this? Anything I can do to help? Thanks

Oleksii Khomchenko
October 7, 2018, 9:08 AM

Has added some docs.

Oleksii Khomchenko
October 7, 2018, 12:44 AM

Ah, I've asked mostly for contributors page not displaying me issue

Sean Corfield
October 7, 2018, 12:25 AM

I asked Alex to check the recent CAs submitted – I expect he'll be able to confirm next week. It'll take me a while to review and analyze the patch anyway (and I'm neck-deep in production roll-outs right now so be patient).


Sean Corfield


Oleksii Khomchenko






Code and Test