Ehcache Disk Store Deletes During Application Restart

I have an ehcache setting that works fine, except that the permanent drive data is deleted every time I restart the application / server (Spring application on TcServer / Tomcat). The whole point of using persistent disk storage was to keep the cache, despite restarting the application.

Here is my ehcache.xml

<?xml version="1.0" encoding="UTF-8"?><ehcache><diskStore path="java.io.tmpdir/ehcache"/><cache name="clusterCache" maxElementsInMemory="1" maxElementsOnDisk="50" eternal="true" overflowToDisk="true" diskPersistent="true" memoryStoreEvictionPolicy="LFU"/></ehcache> 

Any ideas why this is happening?

+6
java ehcache
source share
1 answer

As the documentation notes, Ehcache does not write the index file that it searches for recovery from disk, unless the cache is set properly shutdown, either using the VM shutdown hook, or (since this is in the servlet container) that the servlet context listener provides. See the Ehcache documentation at close for details , although this just means adding below to your web.xml:

 <listener> <listener-class>net.sf.ehcache.constructs.web.ShutdownListener</listener-class> </listener> 
+4
source share

All Articles