目录
3.UserMapper.xml中配置cache的type属性
4.在classpath下加入ehcache.xml配置文件
缓存都是实现了Cache这个接口。
1.SqlMapConfig.xml中开启二级缓存
<!-- 全局配置参数 -->
<settings>
<!-- 打开延迟的开关 -->
<setting name="lazyLoadingEnabled" value="true"/>
<!-- 将积极加载改为消极加载 -->
<setting name="aggressiveLazyLoading" value="false"/>
<!-- 开启二级缓存 -->
<setting name="cacheEnabled" value="true"/>
<!-- 配置日志 -->
<setting name="logImpl" value="LOG4J"/>
</settings>
2.导入相关jar包
3.UserMapper.xml中配置cache的type属性
<!-- 开启本mapper的namespace下的二级缓存 -->
<cache type="org.mybatis.caches.ehcache.EhcacheCache"/>
4.在classpath下加入ehcache.xml配置文件
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../config/ehcache.xsd">
<diskStore path="F:\develop\ehcache" />
<defaultCache
maxElementsInMemory="1000"
maxElementsOnDisk="10000000"
eternal="false"
overflowToDisk="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
</defaultCache>
</ehcache>