![](/img/trans.png)
[英]What is the timeout for items getting removed from cache when using org.springframework.cache.annotation.Cacheable
[英]Calling a method annotated with @Cacheable (org.springframework.cache.annotation.Cacheable)
當調用帶有@Cacheable注釋的方法(org.springframework.cache.annotation.Cacheable)時,存在於另一個(第三方)項目中的方法將導致以下錯誤。
java.lang.IllegalArgumentException: Cannot find cache named 'usersCache' for CacheableOperation[public com.epsilon.amp.infra.model.AuthUser com.epsilon.amp.infra.dao.ContextDao.loadContextUser(java.lang.String,java.lang.String)] caches=[usersCache] | key='' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless=''
第三方項目上方法的注釋如下
@Cacheable("usersCache")
@Transactional(readOnly = true)
@Override
在我的項目中添加注釋並啟用緩存並不能解決問題。 可能出了什么問題?
我建議您創建這樣的配置:
@Configuration
public class CacheService extends CachingConfigurerSupport {
@Bean
public CacheManager cacheManager() {
ConcurrentMapCacheManager cacheManager = new ConcurrentMapCacheManager() {
@Override
protected Cache createConcurrentMapCache(final String name) {
return new ConcurrentMapCache(name,
CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.MINUTES).maximumSize(100).build().asMap(), false);
}
};
return cacheManager;
}
@Bean
@Primary
public CacheManager guavaCacheManager() {
return new GuavaCacheManager();
}
}
之后,必須在要緩存方法的類的開頭添加此批注。
@Cacheable(cacheNames = "guavaCacheManager")
在您的Application類的開頭,此注釋為: @EnableCaching
番石榴信息: https : //github.com/google/guava
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.