SriHarish
SriHarish

Reputation: 311

EhCache and Database Refresh

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

Upvotes: 2

Views: 2641

Answers (1)

aweigold
aweigold

Reputation: 6879

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

Upvotes: 4

Related Questions