配置ehcache.xml时注意,这个地方之前参考其他博文,有个坑。。timeToIdleSeconds、timeToLiveSeconds这两个属性要注意一下,反正我是被坑惨了,一些博文的配置为timeToIdleSeconds=5,timeToLiveSeconds=5,测试的时候每次都有缓存,结果每次都会重新查询,一直没发现问题所在,偶然之下看到这两属性才发现错误。详细情况请看http://blog.youkuaiyun.com/vtopqx/article/details/8522333这篇博文,写得比较具体。
<ehcache> <!-- 磁盘缓存位置 --> <diskStore path="java.io.tmpdir/ehcache"/> <!-- 默认缓存 --> <defaultCache maxEntriesLocalHeap="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" maxEntriesLocalDisk="10000000" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU"/> <cache name="myCache" maxElementsInMemory="10000" maxElementsOnDisk="1000" eternal="false" overflowToDisk="true" diskSpoolBufferSizeMB="20" timeToIdleSeconds="300" timeToLiveSeconds="600" memoryStoreEvictionPolicy="LFU" /> </ehcache>