Suggested usage subject to Cache Stampede
I've been trying to wrap my head around core.cache, and it seems to me that the suggest use in the documentation, i.e.
will result in a Cache Stampede since (retrieve-data key) might be called multiple times if swap! retries due to compare-and-swap misses. Unfortunately I don't have a suggestion on how this could be fixed.
Released/addressed in 0.8.0 through 0.8.2 (0.8.0 and 0.8.1 both had bugs in the wrapped API that are fixed in 0.8.2).
Addition of clojure.core.cache.wrapped with comparable API plus lookup-or-miss to provide stampede-free version of this functionality for caches wrapped in atoms.
The local delay version would look like this:
It took me a while to find this suggested usage – https://github.com/clojure/core.cache/wiki/Using
I should update that to use through-cache which is more idiomatic now:
It would still suffer from the same possibility of Cache Stampede but at least it would be consistent with the newer API.
I suspect using a local delay would mitigate the stampede issue but it would make for very ugly code and it would not play well with through-cache – so I'll have to give that some thought.