Redo Spring cache?

2

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.

    
asked by anonymous 09.03.2017 / 07:16

1 answer

3

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 .

    
09.03.2017 / 13:15