ibatis查询缓存

SqlMapConfig.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
    "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">

<sqlMapConfig>
<!--cacheModelsEnabled      = 启用SqlMapClient上的缓存机制-->
<!--classInfoCacheEnabled   = 保存缓存类,减少类的重用-->
<!--statementCachingEnabled = iBATIS 2.3.0以后版本中有 ,启动预处理缓存机制-->
<!--enhancementEnabled		= 针对POJO启用字节码增强机getter/setter的调用效能-->
<!--lazyLoadingEnabled		= 启用延迟加载机制-->
<!--useStatementNamespaces	= 使用Statement命名空间-->
<!--errorTracingEnabled		= 启用错误日志,方便开发阶段调试-->
<!--maxRequests				= 最大并发请求数(Statement并发数)-->
<!--maxSessions				= 最大Session数。即当前最大允许的并发SqlMapClient数-->
<!--maxTransactions			= 最大并发事务数-->
<settings  
	cacheModelsEnabled="true"  
   	classInfoCacheEnabled="true"
   	statementCachingEnabled="true"  
   	enhancementEnabled="true"  
   	lazyLoadingEnabled="true" 
   	useStatementNamespaces="true" 
   	errorTracingEnabled="true" 
/>
    <sqlMap resource="com/caiyl/src/dao/student.xml"/>			
</sqlMapConfig>

student.xml:

	<sqlMap namespace="student">
		<typeAlias alias="student" type="com.caiyl.Student" />
		<!-- 配置缓存模型 -->
		<cacheModel id="stu-cache" type="OSCache" readOnly="true"
			serialize="true">
			<!-- 设定缓存存活的时间   -->
			<flushInterval hours="24" />
			<!-- 指定DML操作,清空缓存 --> 
			<flushOnExecute statement="insertStu" />
			<flushOnExecute statement="updateStu" />
			<flushOnExecute statement="deleteStu" />
			<!-- 缓存的容量(对象) -->  
			<property value="500" name="size" />
		</cacheModel>
		<resultMap id="StudentMap" class="student">
			<result property="id" column="ID" />
			<result property="name" column="NAME" />
		</resultMap>
		<!-- cacheModel指定使用的缓存id -->
		<select id="selectAllUser" resultMap="StudentMap" cacheModel="stu-cache">
			select * from student
		</select>
		<insert id="insertStu" parameterClass="student">
			insert into student(Id,name) VALUES (#id#, #name#)
		</insert>
		.......
	</sqlMap>
此时ibatis相同的sql只会执行一次


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值