Spring Cache: Evict multiple caches

user655145 picture user655145 · Aug 19, 2014 · Viewed 29.5k times · Source

I'm using Spring Cache abstraction and I have multiple caches defined. Sometimes, when data changes, I want to evict more than one caches. Is there away to evict multiple cache using Spring's @CacheEvict annotation?

Answer

Jaiwo99 picture Jaiwo99 · Aug 19, 2014

You can do this:

@Caching(evict = {
    @CacheEvict("primary"),
    @CacheEvict(value = "secondary", key = "#p0")
})

Check out the Reference for details