Preventing refresh from happening if one is already going #1892
-
|
If this has been asked before, please just link me. In the current implementation of my async caffeine cache, I am using refreshAfterWrite to return stale cache entries while fresh ones are fetched in the background. Since my cache is hydrated on startup, all entries have a similar expiration and it takes a while to refresh all entries when they expire. When I hit the cache while a refresh is happening, it looks like it kicks off another refresh. Is there a way to prevent this from happening? Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
In v3.x it will only perform one refresh per key as it maintains a second mapping. In previous versions it couldn't dedupe on an explicit If you want more control then you can coalesce, jitter, etc. by defining the Hope that helped? |
Beta Was this translation helpful? Give feedback.
In v3.x it will only perform one refresh per key as it maintains a second mapping. In previous versions it couldn't dedupe on an explicit
LoadingCache.refresh(key), only for implicit ones byrefreshAfterWrite. If there is an explicit write, like put or remove, then the in-flight refresh for that key will be abandoned and discarded (this maintains linearizability).If you want more control then you can coalesce, jitter, etc. by defining the
asyncReloadmethod. See this example which groups individual refreshes into a time/space window for a batch call. Since the cache has a handle to a future you can rate limit it, batch, retry and backoff, etc. as you see fit.Hope that helped?