mybatis+ehcache

spring自身集成了对ehcache的管理,需要在配置文件里配置 

1.<cache:annotation-driven cache-manager="cacheManager" proxy-target-class="true"/>    2.ehcachemanager

3.EhCacheManagerFactoryBean。

具体细节http://jinnianshilongnian.iteye.com/blog/2001040

mybatis集成ehcache就相对比交简单了。他不需要配置上面3个。配置映射文件中

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"   
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">  

<mapper namespace="testpojo.com.chit.test.dao.UserDao" >
   <cache type="org.mybatis.caches.ehcache.EhcacheCache"/> <!-- 选其一 -->
<cache type="org.mybatis.caches.ehcache.LoggingEhcache"/>
   <insert id="insert" parameterType="UserModel">
   		insert into test.tab_user(name,sex,age) value(#{name},#{sex},#{age})
   </insert>
   <delete id="delete" parameterType="int">
   		delete from test.tab_user where id =#{0}
   </delete>
 
</mapper>

 还需要配置ehcache.xml配置文件,必须放在classpath个目录下 否则缓存将失效。具体配置给段代码

<?xml version="1.0" encoding="UTF-8"?>  
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"  
    monitoring="autodetect">  
    <!--  
    <diskStore path="java.io.tmpdir" /> -->  
    <diskStore path="j:/cachetmpdir"/>  
    <defaultCache maxElementsInMemory="10000" eternal="false"  
        timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="false"  
        maxElementsOnDisk="10000000" diskPersistent="false"  
        diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" />  
          
    <cache name="andCache" maxElementsInMemory="1"  
        maxElementsOnDisk="1000" eternal="false" overflowToDisk="true"  
        diskSpoolBufferSizeMB="20" timeToIdleSeconds="300" timeToLiveSeconds="600"  
        memoryStoreEvictionPolicy="LFU" />  
   
</ehcache>  

 

你可能感兴趣的:(ehcache,mybatis缓存,spring ehcache)