EhCache and Database Refresh

ⅰ亾dé卋堺 提交于 2019-12-08 02:45:33

问题


I am using Spring and ehcache. using a query I populate the data into the Cache, this process has to happen every 10 mins. Is there a configuration to set this??

Thanks in Advance


回答1:


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();
}


来源:https://stackoverflow.com/questions/8787972/ehcache-and-database-refresh

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