I am trying to write an application to cache which reloads every few seconds. I decided to use spring boot Caffeine and got a sample application too. But when I am specifying refreshAfterWrite property, it throws exception: refreshAfterWrite requires a LoadingCache
spring:
cache:
cache-names: instruments, directory
caffeine:
spec: maximumSize=500, expireAfterAccess=30s, refreshAfterWrite=30s
To resolve this I provide Loading Cache Bean, but cache stopped working altogether:
@Bean
public CacheLoader<Object, Object> cacheLoader() {
return string -> {
System.out.println("string = " + string);
return string;
};
}
@Bean
public LoadingCache<Object, Object> loader(CacheLoader<Object, Object> cacheLoader) {
return Caffeine.newBuilder()
.refreshAfterWrite(1, TimeUnit.SECONDS)
.build(cacheLoader);
}
Do we have some simple way for reload to work?