Search code examples
javaspringcachingspring-cachespring-scheduled

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() {
    ...
}

Solution

  • You can use @Scheduled:

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