OwlFocus

ehcache 持久化

持久化

将diskPersistent属性设置成true,可将缓存内容缓存到磁盘中。

1
2
3
4
5
6
7
8
9
10
11
<?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>

系统配置

在jvm重新启动时,需要重新加载磁盘中的缓存,可以在web.xml中配置如下:

1
2
3
<listener>
<listener-class>net.sf.ehcache.constructs.web.ShutdownListener</listener-class>
</listener>