更新时间:2023-02-02 22:15:51
通常,ehCache将用于给出一个ttl使您的缓存自动失效。根据我从您的问题中得到的信息,您要求每十分钟自动刷新一次缓存。为此,我将运行一项逐出并重新加载的计划服务。例如:
Typically, ehCache would be used to give a ttl to invalidate your cache automatically. From what I can gather from your question, you are asking to automatically refresh the cache every ten minutes. For that, I would run a scheduled service that evicts and reloads. For example:
@Cachable("Foo")
public Foo getFoo() {
...
}
@CacheEvict("Foo")
public void evictFoo(){
...
}
@Scheduled(fixedRate = 10L * 60L * 1000L) //Ten minutes
public void automaticCacheRefresh(){
evictFoo();
getFoo();
}