簡體   English   中英

如何使用JCache批注@CacheRemoveAll清除多個緩存?

[英]How can I clear multiple caches using JCache annotation @CacheRemoveAll?

我有一個方法的執行者應該清除Spring + JCache + ehcache 3.5項目中的兩個緩存。

我試過了:

@CacheRemoveAll(cacheName = "cache1")
@CacheRemoveAll(cacheName = "cache2")
public void methodToBeCalled(){
}

@CacheRemoveAll(cacheName = "cache1", cacheName = "cache2")
public void methodToBeCalled(){
}

首先,我得到:

Duplicate annotation of non-repeatable type @CacheRemoveAll

在第二個中我得到:

Duplicate attribute cacheName in annotation @CacheRemoveAll

你不能 注釋不能重復,屬性也不能重復。

您將需要@CacheRemoveAlls批注,但框架尚未計划。

最好的解決方案就是在methodToBeCalled的開頭為兩個緩存調用removeAll

代碼如下:

public class MyClass {
    @Autowired
    private CacheManager cacheManager; // this is a Spring CacheManager

    public void methodToBeCalled(){
        cacheManager.getCache("cache1").clear();
        cacheManager.getCache("cache2").clear();
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM