Caches of all versions of a webapp deployed in parallel are shutdowned

466 views Asked by At

I use ehcache in a webapp whose versions are deployed in parallel on a Tomcat instance. This is a handy way to deploy new versions without stopping an application.

I however have a problem with this way to proceed : even if I give the cache and disk store different names, depending on the versions of the webapp, all caches are stopped when stopping one instance.

My config is :

<?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>

${project.version} and ${buildNumber}

being replaced by maven during the build process.

Does someone know how to avoid this unwanted behaviour ?

I am using ehcache-core-2.4.3 and hibernate-ehcache-4.3.8.

2

There are 2 answers

2
Louis Jacomet On BEST ANSWER

The way net.sf.ehcache.constructs.web.ShutdownListener works is by shutting down ALL cache managers.

So the only way for this to work for you is by making sure your cache managers end up in different class loaders, that is ehcache is loaded by the web application class loader and not the container one.

Do you provide ehcache jar in your app's WEB-INF/lib? If yes, are you sure there is not an Ehcache in tomcat's classpath?

If this solution still does not work, you may be better off creating your own ServletContextListener that would shutdown only the cache manager from the containing application.

1
sach On

Some details are missing from your query.

1)How are you stopping the cache?

2)How are you deploying application in tomcat?

3)Have you checked the location where does the cache object is created ?

But as a behavior all cache will cleared once you restart tomcat.