phu*_*ury 6 java spring ehcache
我使用ehcache和注释驱动配置配置了spring方法缓存.
但是,我希望能够从我们在应用程序中使用的配置文件中禁用它.
我的第一个想法是,net.sf.ehcache.CacheManager.CacheManager()如果禁用方法缓存,则不带参数调用.抛出异常:
java.lang.IllegalArgumentException: loadCaches must not return an empty Collection
at org.springframework.util.Assert.notEmpty(Assert.java:268)
at org.springframework.cache.support.AbstractCacheManager.afterPropertiesSet(AbstractCacheManager.java:49)
Run Code Online (Sandbox Code Playgroud)
我的第二个想法是配置net.sf.ehcache.CacheManager.CacheManager()默认数据,以便不使用缓存(maxElementsInMemory 0等).但是仍然使用缓存,这不是我想要的.
有一个属性,net.sf.ehcache.disabled但我不想禁用也使用ehcache的hibernate缓存.
Q如何配置所有内容以使用spring方法缓存但从外部配置文件中禁用它?我不想修改应用程序上下文,也不想修改启用/禁用方法缓存的代码.只能修改我们在应用程序中使用的配置文件.
我在寻找的是NoOpCacheManager:
为了使它工作,我从xml bean创建切换到工厂
我做了如下的事情:
@Bean
public CacheManager cacheManager() {
final CacheManager cacheManager;
if (this.methodCacheManager != null) {
final EhCacheCacheManager ehCacheCacheManager = new EhCacheCacheManager();
ehCacheCacheManager.setCacheManager(this.methodCacheManager);
cacheManager = ehCacheCacheManager;
} else {
cacheManager = new NoOpCacheManager();
}
return cacheManager;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5504 次 |
| 最近记录: |