1、首先设置EhCache,建立配置文件ehcache.xml,默认的位置在class-path,可以放到你的src目录下:
1 2 3 4 5 6 7 8 9 10 11 12 |
<?xml version="1.0" encoding="UTF-8"?> <ehcache> <diskStore path="java.io.tmpdir"/> <defaultCache maxElementsInMemory="10000" <!-- 缓存最大数目 --> eternal="false" <!-- 缓存是否持久 --> overflowToDisk="true" <!-- 是否保存到磁盘,当系统当机时--> timeToIdleSeconds="300" <!-- 当缓存闲置n秒后销毁 --> timeToLiveSeconds="180" <!-- 当缓存存活n秒后销毁--> diskPersistent="false" diskExpiryThreadIntervalSeconds= "120"/> </ehcache> |