mybatis 启用 ehcache 缓存
411人浏览 / 0人评论
pom.xml
<!--ehcache-->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.10.6</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-ehcache</artifactId>
<version>1.0.0</version>
</dependency>
ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
<!--使用ehcache缓存需要在mapper.xml文件中添加:
<cache type="org.mybatis.caches.ehcache.LoggingEhcache"/>
-->
<defaultCache overflowToDisk="true" eternal="false"
maxElementsInMemory="1"
timeToLiveSeconds="10"
maxEntriesLocalHeap="1000"
maxEntriesLocalDisk="10000000"
memoryStoreEvictionPolicy="LRU"/>
<diskStore path="d:/myProject/cache" />
</ehcache>
*Mapper.xml
<!--开启二级缓存-->
<cachetype="org.mybatis.caches.ehcache.LoggingEhcache"/>
全部评论