Mybatis中使用ehcache

maven

<!-- 二級緩存 -->
<dependency>
    <groupId>org.mybatis.caches</groupId>
    <artifactId>mybatis-ehcache</artifactId>
    <version>1.0.3</version>
</dependency>
<dependency>
    <groupId>net.sf.ehcache</groupId>
    <artifactId>ehcache-core</artifactId>
    <version>2.6.10</version>
</dependency>

ehcache.xml

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd">    
  <diskStore path="java.io.tmpdir"/>    
  <defaultCache  
    maxElementsInMemory="10000"  
    eternal="false"  
    timeToIdleSeconds="120"  
    timeToLiveSeconds="120"  
    overflowToDisk="true"  
    maxElementsOnDisk="10000000"  
    diskPersistent="false"  
    diskExpiryThreadIntervalSeconds="120"  
    memoryStoreEvictionPolicy="LRU"  
    />  
</ehcache>  

SqlMapConfig.xml

新版本的Mybatis默認是開啓的,所以就不用寫了

<setting name="cacheEnabled" value="true" />

在Mapper文件中使用二級緩存

<!-- 開啓二級緩存 -->
<cache type="org.mybatis.caches.ehcache.EhcacheCache" />
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章