是否可以使用多个ehcache.xml(在不同的项目中,同一场战争中)?

发布于 12-26 06:35 字数 1114 浏览 5 评论 0原文

我有一个服务项目和一个网络项目。我需要在两个项目中都有 eh-cache 。

这个想法是,如果服务项目更新,则与缓存相关的更改(如密钥和失效规则)也将可用,而不会对 Web 项目进行任何更改。由于如此独立,服务项目也可以与其他项目一起使用,而他们甚至不知道 eh-cache。

此时,我的Web项目也使用eh-cache来达到自己的目的。我对 eh-cache 没有太多经验,我担心这两个项目一起部署时可能会发生冲突。我在eh-cache网站上也没有找到相关信息。

您能否向我提供一些如何最好地配置这两个项目的信息,以便我能够实现上述要求?


编辑:

我正在使用 Spring,因此我更喜欢将它用于我的缓存管理器。

我在 context.xml 中为每个带有 ehcache 的 jar 使用以下内容,例如 jar 1 我有:

<ehcache:annotation-driven cache-manager="ehCacheManager1" />

<bean id="ehCacheManager1" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="classpath:ehcache-1.xml" />
</bean>

对于 jar 2 我有

<ehcache:annotation-driven cache-manager="ehCacheManager2" />

<bean id="ehCacheManager2" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="classpath:ehcache-2.xml" />
</bean>

那么,两个缓存都会启动并工作吗?我担心 ehcache:annotation-driven 会被最后一次读取的上下文覆盖,并且只有一个缓存可以运行。我错了,还是错过了什么?

I have a services project and a web project. I need to have eh-cache in both projects.

The idea is that if the service project is updated, it's cache-related changes (like keys and invalidation rules) will also be available, while no changes are made to the web project. Being so independent, the service project can also be used with another projects without them even knowing of eh-cache.

At this point, my web project also uses eh-cache for its own purposes. I am not much experienced with eh-cache and I fear that the two projects might clash when deployed together. I also did not find relevant information on eh-cache site.

Can you provide me some information how to best configure the two projects, so that I can achieve the above requirements?


Edit:

I am using Spring, therefore I will prefer to use it for my cache managers.

I am using the following in the context.xml for each jar with ehcache, for instance for
jar 1 I have:

<ehcache:annotation-driven cache-manager="ehCacheManager1" />

<bean id="ehCacheManager1" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="classpath:ehcache-1.xml" />
</bean>

and for jar 2 I have

<ehcache:annotation-driven cache-manager="ehCacheManager2" />

<bean id="ehCacheManager2" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="classpath:ehcache-2.xml" />
</bean>

So, will both caches be up and working? I fear the ehcache:annotation-driven will get overridden by the last read context and only one cache will be operational. Am I wrong, or missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

注定孤独终老2025-01-02 06:35:46

ConfigurationResourceName 属性用于指定 ehcache 配置文件的位置。在类路径的根目录中搜索资源。它用于在同一虚拟机中支持多个 CacheManager。

net.sf.ehcache.configurationResourceName=/name_of_ehcache.xml

The configurationResourceName property is used to specify the location of the ehcache configuration file.The resource is searched for in the root of the classpath. It is used to support multiple CacheManagers in the same VM.

net.sf.ehcache.configurationResourceName=/name_of_ehcache.xml
嗼ふ静2025-01-02 06:35:46

尝试在 ehcache.xml 中以不同的方式命名两个 cacheManager

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    name="ehCacheManager1">


<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    name="ehCacheManager2">

Try naming both cacheManagers differently in ehcache.xml

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    name="ehCacheManager1">


<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    name="ehCacheManager2">
呢古2025-01-02 06:35:46

如果您对不同的 WAR 使用不同的缓存并且希望防止冲突,请转到每个 WAR 的 echcache.xml 并在 cacheManagerPeerProviderFactory 元素下定义不同的multicastGroupPort 值。也禁用分发。

祝你好运!

if you use different cache for different WAR and you want to prevent collisions, go to echcache.xml of each WAR and define different multicastGroupPort values under cacheManagerPeerProviderFactory element. also disable distribution.

Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文