title: How can I evict ALL cache in Spring Boot?
body: <p>On app start, I initialized ~20 different caches:</p>
  
  <pre><code>@Bean
  public CacheManager cacheManager() {
      SimpleCacheManager cacheManager = new SimpleCacheManager();
      cacheManager.setCaches(Arrays.asList(many many names));
      return cacheManager;
  }
  </code></pre>
  
  <p>I want to reset all the cache at an interval, say every hr. Using a scheduled task:</p>
  
  <pre><code>@Component
  public class ClearCacheTask {
  
      private static final Logger logger = LoggerFactory.getLogger(ClearCacheTask.class);
      private static final DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd hh:mm:ss");
  
      @Value("${clear.all.cache.flag}")
      private String clearAllCache;
  
      private CacheManager cacheManager;
  
      @CacheEvict(allEntries = true, value="...............")
      @Scheduled(fixedRate = 3600000, initialDelay = 3600000) // reset cache every hr, with delay of 1hr
      public void reportCurrentTime() {
          if (Boolean.valueOf(clearAllCache)) {
              logger.info("Clearing all cache, time: " + formatter.print(DateTime.now()));
          }
      }
  }
  </code></pre>
  
  <p>Unless I'm reading the docs wrong, but  <code>@CacheEvict</code> requires me to actually supply the name of the cache which can get messy.</p>
  
  <p>How can I use  <code>@CacheEvict</code> to clear ALL caches?</p>
  
  <p>I was thinking instead of using  <code>@CacheEvict</code>, I just loop through all the caches:</p>
  
  <pre><code>cacheManager.getCacheNames().parallelStream().forEach(name -&gt; cacheManager.getCache(name).clear());
  </code></pre>