ExpireAfter will only purge the item but will not re-create the item. So what I need to do is, after a predefined interval, I need to purge a particular item from the cache and at the same time I need to recreate it. It might recreate with same data if there is no change in the data. Assuming the data was changed, the recreating will give the latest object.
My idea was to retrieve latest item form the cache all the time. In contrast, the Refresh feature (https://github.com/ben-manes/caffeine/wiki/Refresh) will provide the stale item for the first request and does an asynchronous loading. So for the second request the cache will provide the latest object.
- Asynchronous removal listener that re-fetches the expired entry should work in my case. Can you please provide me some information on how to achieve this?
- I'm also curious to know how the scheduled task can do it?
Assuming cache can address the following two cases:
Subsequent requests case:
I understand the refreshAfterWrite will provide the stale entry for the first time but for the second request, what happens if the cache hasn't yet completed loading the expired entry?
Does cache blocks the second request, completes the re-fetch, and then provide the latest value to the second request?.
The idea is to make the cache provides the latest data after the defined entry expiry time.
In the case where the cache has to load values equal to its capacity at one shot:
Let say the cache size is 100 and the time to load all the 100 items is 2 minutes.
Assuming the first request would load 100 items into the cache at the same time, after the defined expiry time, the cache should evict and re-fetch all the 100 elements.
For the second request to access items from those 100 items, how can I make the cache smart enough so that it returns the entries that have been re-loaded and asynchronously re-loads the other entries?.
The idea is not to block any request for an existing entry. Serve the request for an existing entry and do the re-load for the remaining expired entries.