I am using Caffeine LoadingCache to cache expensive IO operation, which could take a long time:
var cache = Caffeine
.refreshAfterWrite(1, MINUTES)
.build(loader);
and try to get the values using cache.get(k)
.
When a cached entry exist, but already marked for refresh (more than 1 min), and then I call get
, does it block and try to load from the loader, or does it return the cached value immediately and load in the background thread?
I've tried to look in the documentations and I don't find a clear explanation of this. Refresh only mentions when you call refresh
, but not when you call get
. In my reasoning, since refreshAfterWrite
does not evict the "expired" entries, it should make use of it and return that cached value without blocking, but I did not find confirmation.
The doc you linked says
The old value (if any) is still returned while the key is being refreshed, in contrast to eviction, which forces retrievals to wait until the value is loaded anew.
This is referring to get
.