你在使用Spring Cache吗?然后 将true设置为allEntries属性
@Cacheable("myCache") public String getCache() { try { Thread.sleep(3000); } catch (final InterruptedException e) { } return "aaa"; } @CacheEvict(cacheNames = "myCache", allEntries = true) public void evictAll() { }
或者如果要删除您定义的所有缓存
@Autowired CacheManager cacheManager; public void evictAll() { cacheManager.getCacheNames() .stream() .forEach(n -> cacheManager.getCache(n).clear()); }