ehcache是一个分布式缓存框架,是hibernate中二级缓存的默认实现。
一,整合的思路
mybatis提供了一个cache接口,如果要实现自己的缓存逻辑,实现cache接口开发即可:
mybatis和ehcache整合:mybatis和ehcache的整合包中提供了一个cache接口的实现类:
1,加入jar
2,整合ehcache
mapper.xml中配置:
<!--
type:指定cache接口的实现类的类型,mybatis默认使用PertualCache和Cache整合,
需要配置type为org.mybatis.caches.ehcache.EhcacheCache
来实现Cache接口
-->
<cache type="org.mybatis.caches.ehcache.EhcacheCache"/>
3,加入ehcache.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../config/ehcache.xsd">
<diskStore path="H:\ehcache" />
<defaultCache
maxElementsInMemory="1000"
maxElementsOnDisk="10000000"
eternal="false"
overflowToDisk="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
</defaultCache>
</ehcache>
ok~