gpt4 book ai didi

java - ehcache - 限制访问

转载 作者:行者123 更新时间:2023-12-01 11:34:26 25 4
gpt4 key购买 nike

我在我的应用程序中使用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>

是否可以控制访问?

感谢您的帮助!

问候,
五、

最佳答案

一般情况下,应用程序无法相互访问,因为它们加载了单独的类路径(您可以阅读更多相关信息 here ),因此您不必担心。

您必须付出额外的努力才能使简单的缓存管理器在所有应用程序中可用(例如通过 JNDI 使其可用或将其放入共享库中)

关于java - ehcache - 限制访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30148935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com