EhCache and Database Refresh

2019-05-28 11:08发布

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条回答
兄弟一词,经得起流年.
2楼-- · 2019-05-28 11:44

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();
}
查看更多
登录 后发表回答