Java Spring Cache:驱逐多个缓存

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25379051/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 00:16:10  来源:igfitidea点击:

Spring Cache: Evict multiple caches

javaspringspring-cache

提问by

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 @CacheEvictannotation?

我正在使用 Spring Cache 抽象,并且定义了多个缓存。有时,当数据发生变化时,我想驱逐多个缓存。是否可以使用 Spring 的@CacheEvict注释驱逐多个缓存?

采纳答案by Jaiwo99

You can do this:

你可以这样做:

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

Check out the Referencefor details

查看参考以了解详细信息

回答by yglodt

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

保持紧凑:您可以通过在@CacheEvict注释中枚举它们来驱逐多个缓存:

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