Is it possible to schedule the Spring cache to be redone at midnight every time?
I've read the Springs Cache Docs and found nothing about how to get it back.
Is it possible to schedule the Spring cache to be redone at midnight every time?
I've read the Springs Cache Docs and found nothing about how to get it back.
Something that could be done is to use cache expiration ( @CacheEvict
) in conjunction with the schedule ( Scheduled
), as below:
@Configuration
@EnableCaching
@EnableScheduling
public class CachingConfig {
public static final String GAMES = "GAMES";
@Bean
public CacheManager cacheManager() {
ConcurrentMapCacheManager cacheManager = new ConcurrentMapCacheManager(GAMES);
return cacheManager;
}
@CacheEvict(allEntries = true, value = {GAMES})
@Scheduled(cron = "* * 0 * * ?")
public void reportCacheEvict() {
System.out.println("Flush Cache " + dateFormat.format(new Date()));
}
}
Based on in this answer .