开发者

Ehcache diskstore is deleted during application restart

开发者 https://www.devze.com 2023-01-01 23:50 出处:网络
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 o

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 i开发者_如何学JAVAdeas why this is happening?


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

精彩评论

暂无评论...
验证码 换一张
取 消