Wednesday, December 12, 2018

Spring: Clean up CacheManager Java code


If you had use @Cacheable for your java method, and would like clear the cache on run time.
AND If you are able to execute a groovy script, following solution is for you

Groovy Script

import org.springframework.cache.CacheManager;
cacheManager = spring.getBean("cacheManager");

for(String name:cacheManager.getCacheNames()){
            cacheManager.getCache(name).clear();
}