user655145
user655145

Reputation:

Spring Cache: Evict multiple caches

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?

Upvotes: 46

Views: 47622

Answers (2)

Jaiwo99
Jaiwo99

Reputation: 10017

You can do this:

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

Check out the Reference for details

Upvotes: 96

yglodt
yglodt

Reputation: 14551

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

@CacheEvict(value = { "cache1", "cache2" }, allEntries = true)

Upvotes: 56

Related Questions