W
W
web_dev2012-11-26 20:07:55
Java
web_dev, 2012-11-26 20:07:55

Spring @Cacheable - remove(clear) all cache?

Tell me, is there any method to delete the entire cache?
I saw that you can call the CacheManager to load all the names of the cache into it and then delete one by one, how to implement it? I don't know how to get cache from ehcache.xml.
Let's say there are 2 caches defined, how to delete them with one call?
Cache by name can be deleted @CacheEvict(value = "books", allEntries=true)
Here are the config settings:

<!-- cache setup -->
  <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:config-location="classpath:ehcache.xml" />
  <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cacheManager-ref="ehcache" />

Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
serso, 2012-11-26
@serso

Get a bean with id=cacheManager and do whatever you want - EhCacheCacheManager provides an interface to work with the cache by name.

W
web_dev, 2012-11-26
@web_dev

For now, this is how it works.
@CacheEvict(value = {"faqCache", "faqCategoryCache", "faqTopCache"}, allEntries=true)
What if, for example, there are 100 values?
You need to somehow knock through the manager ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question