Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ehcache diskstore is deleted during application restart

Tags:

java

ehcache

I have an ehcache setup, that works just fine, except that the persistent diskstore data is removed everytime I restart my application/server (Spring application on TcServer/Tomcat). The whole point of using the persistent diskstore was to be able to persist the cache in spite of application restarts.

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?

like image 430
chrismarx Avatar asked Jun 03 '10 23:06

chrismarx


1 Answers

As the documentation notes, Ehcache doesn't write the index file that it looks for to restore from the disk unless the cache is properly shutdown, either via a VM shutdown hook or (since this is in a servlet container) the servlet context listener it provides. See the Ehcache documentation on shutting down for details, though it just means adding the below to your web.xml:

<listener>
      <listener-class>net.sf.ehcache.constructs.web.ShutdownListener</listener-class>
</listener> 
like image 181
ig0774 Avatar answered Oct 14 '22 00:10

ig0774