Suggested usage subject to Cache Stampede

Description

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.

Environment

None

Activity

Show:
Sean Corfield
November 1, 2019, 4:51 PM

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).

Sean Corfield
August 24, 2019, 10:34 PM

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.

Sean Corfield
October 3, 2018, 6:56 AM

The local delay version would look like this:

Sean Corfield
September 22, 2018, 7:41 PM

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.

Fixed

Assignee

Sean Corfield

Reporter

import