EhCache and Database Refresh

China☆狼群 提交于 2019-12-06 13:15:38

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();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!