【发布时间】:2015-05-10 16:01:59
【问题描述】:
我在我的应用程序中使用 ehcache(未复制或分布式),据我所知,它只能从同一个 JVM 访问,但同一个 JVM 中的所有应用程序(例如部署在应用服务器中)都可以从缓存中获取值.我说的对吗?
我想要的是只有我的应用程序才能获取缓存及其值。有可能吗?我检查了 XML 配置文件,但没有找到任何配置来控制它。或者我应该在从 CacheManager 获取缓存时设置一些东西吗?
这就是我在代码中获取缓存的方式:
private static final String LOCAL_CACHE_NAME = "LOCAL_PROTNEUT_STORE";
private Cache getCache() {
// the name of the ehcache should be able to be configured in the general config XML
URL url = getClass().getResource("/protneut-local-ehcache.xml");
CacheManager manager = CacheManager.create(url);
Cache cache = manager.getCache(LOCAL_CACHE_NAME);
return cache;
}
配置文件:
<ehcache>
<cache name="LOCAL_PROTNEUT_STORE" maxElementsInMemory="500" eternal="true" memoryStoreEvictionPolicy="LRU" />
</ehcache>
是否可以完全控制访问?
感谢您的帮助!
问候,
五、
【问题讨论】: