mybatis-ehcache 用法配置备忘
2016-07-06 14:17
423 查看
1、配置ehcache文件:
(1)当为select语句时:
flushCache默认为false,表示任何时候语句被调用,都不会去清空本地缓存和二级缓存。
useCache默认为true,表示会将本条语句的结果进行二级缓存。
(2)当为insert、update、delete语句时:
flushCache默认为true,表示任何时候语句被调用,都会导致本地缓存和二级缓存被清空。
useCache属性在该情况下没有。
参考地址:http://yedward.net/?id=314
<?xml version="1.0" encoding="UTF-8"?> <ehcache updateCheck="false" name="defaultCache" > <diskStore path="../temp/allcure/ehcache" /> <!-- 默认缓存配置. --> <defaultCache maxEntriesLocalHeap="100" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600" overflowToDisk="true" maxEntriesLocalDisk="1000000" memoryStoreEvictionPolicy="LFU"/> <!-- 系统缓存 --> <cache name="sysCache" maxEntriesLocalHeap="100" eternal="true" overflowToDisk="true" /> </ehcache>2、在spring容器增加缓存配置:
<!-- 缓存配置 --> <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> <property name="configLocation" value="classpath:${ehcache.configFile}" /> </bean>3、在你想要缓存的mapper配置文件里面加入以下内容,该查询语句得到的结果将会被缓存:
<?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="com.demo.DemoMapper"> <!-- 以下两个<cache>标签二选一,第一个可以输出日志,第二个不输出日志 --> <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> <!-- <cache type="org.mybatis.caches.ehcache.EhcacheCache"/> --> <select id="selectUserById" parameterType="int" resultType="com.demo.User" useCache=true"> select * from user where id=#{id} </select> </mapper>注意:在MyBatis中有flushCache、useCache这两个配置属性,分为下面几种情况:
(1)当为select语句时:
flushCache默认为false,表示任何时候语句被调用,都不会去清空本地缓存和二级缓存。
useCache默认为true,表示会将本条语句的结果进行二级缓存。
(2)当为insert、update、delete语句时:
flushCache默认为true,表示任何时候语句被调用,都会导致本地缓存和二级缓存被清空。
useCache属性在该情况下没有。
参考地址:http://yedward.net/?id=314
相关文章推荐
- 页面缓存:内存和文件之间的那些事
- 浅析SQL Server中的执行计划缓存(上)
- Enterprise Library for .NET Framework 2.0缓存使用实例
- PowerShell中编程清空IE缓存方法
- PowerShell中使用.NET将程序集加入全局程序集缓存
- C#中缓存的基本用法总结
- Android实现图片异步加载并缓存到本地
- wap开发中如何有效的利用缓存减少消息的传送量
- PHP基于文件存储实现缓存的方法
- smarty缓存用法分析
- 在ASP.NET 2.0中操作数据之五十九:使用SQL缓存依赖项SqlCacheDependency
- 在ASP.NET 2.0中操作数据之五十八:在程序启动阶段缓存数据
- 在ASP.NET 2.0中操作数据之五十七:在分层架构中缓存数据
- 引用全局程序集缓存内的程序集的方法
- asp Response.flush 实时显示进度
- C#实现清除IE浏览器缓存的方法
- ASP.NET缓存管理的几种方法
- PHP文件缓存类实现代码
- 清除aspx页面缓存的程序实现方法
- C#缓存之SqlCacheDependency用法实例总结