Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring @cacheable how to refresh cache 12am?

I would like to refresh the cache everyday 12am or the cache expired at 12am. I had check the available methods in net.sf.ehcache.config.CacheConfiguration, but these methods i.e. timeToIdleSeconds, timeToLiveSeconds seem like not what I want. May I know how to achieve this?

Edit 1:

Here is how I use @Cacheable.

@Override
@Cacheable(value = "cacheName")
public Object retrieveConfigurations() {
    ...
}
like image 643
karfai Avatar asked Dec 07 '25 09:12

karfai


1 Answers

You can use @Scheduled:

@Scheduled(cron = "<cron expression>")
@CacheEvict(value = "<cache name>")
public void clearCache() {      
}

like image 117
Dzmitry Bahdanovich Avatar answered Dec 09 '25 21:12

Dzmitry Bahdanovich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!