I have a requirement on re cache the expired cache by calling the API again
The below is my cache manager configuration
private CaffeineCache buildCache(
String name,
Ticker ticker,
int minutesToExpire
) {
return new CaffeineCache(name, Caffeine.newBuilder()
.refreshAfterWrite(minutesToExpire, TimeUnit.MINUTES)
.maximumSize(100)
.ticker(ticker)
.build());
}
But while starting the application it is throwing the below exception
Caused by: java.lang.IllegalStateException: refreshAfterWrite requires a LoadingCache
You need to provide a CacheLoader to the build method.
return new CaffeineCache(
name,
Caffeine.newBuilder()
.refreshAfterWrite(minutesToExpire, TimeUnit.MINUTES)
.maximumSize(100)
.ticker(ticker)
.build(key -> createExpensiveObject(key))
);
The CacheLoader is a class/method that has to be implemented by you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With