并行部署的所有Webapp版本的缓存都将被关闭

Lud*_*net 8 java tomcat ehcache

我在webapp中使用ehcache,其版本 Tomcat实例上并行部署.这是在不停止应用程序的情况下部署新版本的便捷方法.

但是我有这样一个问题要继续:即使我给缓存和磁盘存储不同的名称,取决于webapp的版本,所有缓存在停止一个实例时停止.

我的配置是:

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="ehcache.xsd" name="mywebapp-${project.version}_build_${buildNumber}">
<defaultCache
    maxElementsInMemory="1000"
    maxElementsOnDisk="10000"
    eternal="false"
    timeToLiveSeconds="300"
    timeToIdleSeconds="300"
    overflowToDisk="true"
    diskPersistent="false"
    memoryStoreEvictionPolicy="LRU"
    statistics="true"
/>

<cache
    maxElementsInMemory="1000"
    maxElementsOnDisk="10000"
    name="org.hibernate.cache.internal.StandardQueryCache"
    eternal="false"
    timeToLiveSeconds="300"
    timeToIdleSeconds="300"
    overflowToDisk="true"
    diskPersistent="false"
    statistics="true"/>

<cache
    name="org.hibernate.cache.spi.UpdateTimestampsCache"
    maxElementsInMemory="10000"
    maxElementsOnDisk="100000"
    timeToLiveSeconds="300"
    timeToIdleSeconds="300"
    eternal="false"
    overflowToDisk="true"
    diskPersistent="false"
    statistics="true"/>

<cache
    name="query.Presences"
    maxElementsInMemory="100"
    maxElementsOnDisk="1000"
    eternal="false"
    timeToLiveSeconds="300"
    timeToIdleSeconds="300"
    overflowToDisk="true"
    diskPersistent="false"
    statistics="true"/>

<diskStore path="java.io.tmpdir/mywebapp-${project.version}_build_${buildNumber}"/> 

</ehcache>
Run Code Online (Sandbox Code Playgroud)

${project.version}${buildNumber}

在构建过程中被maven取代.

有人知道如何避免这种不受欢迎的行为吗?

我使用的是ehcache-core-2.4.3和hibernate-ehcache-4.3.8.

Lou*_*met 2

有效的方法net.sf.ehcache.constructs.web.ShutdownListener是关闭所有缓存管理器。

因此,这一点对您有用的唯一方法是确保您的缓存管理器最终位于不同的类加载器中,即 ehcache 由 Web 应用程序类加载器加载,而不是由容器类加载器加载。

您在应用程序中提供 ehcache jar 吗WEB-INF/lib?如果是的话,你确定tomcat的类路径中没有Ehcache吗?

如果此解决方案仍然不起作用,您最好创建自己的解决方案ServletContextListener,仅关闭包含应用程序的缓存管理器。