开发者

Ehcache diskstore is deleted during application restart

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜