Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Caffeine non blocking LoadingCache.get for expensive operation

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading