1、jar 和配置文件 maven项目 .pom文件设置
2、resources目录下的config目录下加入 ehcache.xml
配置如下
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" updateCheck="false"
xsi:noNamespaceSchemaLocation="http://ehcache.sf.net/ehcache.xsd">
<diskStore path="java.io.tmpdir/ehcache"/>
<!-- 默认的管理策略
maxElementsOnDisk: 在磁盘上缓存的element的最大数目,默认值为0,表示不限制。
eternal:设定缓存的elements是否永远不过期。如果为true,则缓存的数据始终有效,如果为false那么还要根据timeToIdleSeconds,timeToLiveSeconds判断。
diskPersistent: 是否在磁盘上持久化。指重启jvm后,数据是否有效。默认为false。
diskExpiryThreadIntervalSeconds:对象检测线程运行时间间隔。标识对象状态(过期/持久化)的线程多长时间运行一次。
-->
<defaultCache maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="3600"
overflowToDisk="true"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"/>
<!-- 对象无过期,一个10000长度的队列,最近最少使用的对象被删除 -->
<cache name="sample"
maxElementsInMemory="10000"
eternal="true"
overflowToDisk="true"
diskPersistent="false"
memoryStoreEvictionPolicy="LFU">
</cache>
<cache name="licence"
maxElementsInMemory="10000"
eternal="true"
overflowToDisk="true"
diskPersistent="false"
memoryStoreEvictionPolicy="LFU">
</cache>
</ehcache>
3、项目具体实现 service层 的impl(实现类)里
@Cacheable(key = "#vo.toString()", value="licence")
@Override
public List<CarTotalModel> getData(CarToatlVo vo) {
return carTotalMapper.getData(vo);
}
4、@Cacheable(key = "#vo.toString()", value="licence")是缓存的使用