42

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?

yglodt
  • 13,807
  • 14
  • 91
  • 127

2 Answers2

81

You can do this:

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

Check out the Reference for details

Madbreaks
  • 19,094
  • 7
  • 58
  • 72
Jaiwo99
  • 9,687
  • 3
  • 36
  • 53
53

Keep it compact: You can evict multiple caches by enumerating them inside the @CacheEvict annotation:

@CacheEvict(value = { "cache1", "cache2" }, allEntries = true)
yglodt
  • 13,807
  • 14
  • 91
  • 127