Caches of all webapp versions deployed in parallel are closed.

I use ehcache in webapp, versions of which are deployed in parallel on a Tomcat instance. This is a convenient way to deploy new versions without stopping the application.

However, I have a problem with this path: even if I give the cache and disks different names, depending on the versions of webapp, the caches all stop when they stop alone .

My config:

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

replaced with maven during the build process.

Does anyone know how to avoid this unwanted behavior?

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

+8
java tomcat ehcache
source share
2 answers

The path net.sf.ehcache.constructs.web.ShutdownListener works by disabling all cache managers.

Thus, the only way for you to work is to make sure that your cache managers end up in different class loaders, i.e. ehcache is loaded by the web application class loader, not the container.

Do you provide ehcache jar in your application WEB-INF/lib ? If so, are you sure that there is no Ehcache in the tomcat class path?

If this solution still does not work, you might be better off creating your own ServletContextListener , which will only disable the cache manager from the containing application.

+2
source share

Your request is missing some details.

1) How do you stop the cache?

2) How do you deploy the application to tomcat?

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

But, as a behavior, the entire cache will be deleted after tomcat reboot.

0
source share

All Articles