ibatis缓存配备
ibatis缓存配置
iBATIS里主要是在xml文件里进行一些配置
<cacheModel id=”productCache” type=”LRU”> <flushInterval hours=”24”/> <property name=”size” value=http://blog.soso.com/qz.q/”1000” /> </cacheModel>
cacheModel有四个属性,id,type,serializable,readonly,后两个属性可以设置为true或false
type为缓存的模式,有四种MEMORY,LRU,FIFO,OSCACHE
Xml代码
<cacheModel type="MEMORY">
<flushInterval hours="24"/> //每隔多长时间更新,hours,minutes,seconds等
<flushOnExecute statement="insertProduct"/> //定义的映射id,当执行insertProduct时,执行高速缓存
<flushOnExecute statement="updateProduct"/>
<flushOnExecute statement="deleteProduct"/>
<property name=”reference-type” value=http://blog.soso.com/qz.q/”WEAK” /> //MEMORY cache实现只认识一个<property>元素。这个名为“reference-type”属性的值必须是STRONG,SOFT和WEAK三者其一。
默认是weak,让垃圾处理器去处理
</cacheModel>
<cacheModel type="LRU">
<flushInterval hours="24"/>
<flushOnExecute statement="insertProduct"/>
<flushOnExecute statement="updateProduct"/>
<flushOnExecute statement="deleteProduct"/>
<property name=”size” value=http://blog.soso.com/qz.q/”1000” /> //缓冲区大小
</cacheModel>
<cacheModel type="FIFO">
<flushInterval hours="24"/>
<flushOnExecute statement="insertProduct"/>
<flushOnExecute statement="updateProduct"/>
<flushOnExecute statement="deleteProduct"/>
<property name=”size” value=http://blog.soso.com/qz.q/”1000” />
</cacheModel>
<cacheModel type="OSCACHE">
<flushInterval hours="24"/>
<flushOnExecute statement="insertProduct"/>
<flushOnExecute statement="updateProduct"/>
<flushOnExecute statement="deleteProduct"/>
</cacheModel>
实际用法
Xml代码
<select id=”getProductList” cacheModel=”productCache”>
select * from PRODUCT where PRD_CAT_ID = #value#
</select>
在实际项目中运用时学习吧
iBATIS里主要是在xml文件里进行一些配置
<cacheModel id=”productCache” type=”LRU”> <flushInterval hours=”24”/> <property name=”size” value=http://blog.soso.com/qz.q/”1000” /> </cacheModel>
cacheModel有四个属性,id,type,serializable,readonly,后两个属性可以设置为true或false
type为缓存的模式,有四种MEMORY,LRU,FIFO,OSCACHE
Xml代码
<cacheModel type="MEMORY">
<flushInterval hours="24"/> //每隔多长时间更新,hours,minutes,seconds等
<flushOnExecute statement="insertProduct"/> //定义的映射id,当执行insertProduct时,执行高速缓存
<flushOnExecute statement="updateProduct"/>
<flushOnExecute statement="deleteProduct"/>
<property name=”reference-type” value=http://blog.soso.com/qz.q/”WEAK” /> //MEMORY cache实现只认识一个<property>元素。这个名为“reference-type”属性的值必须是STRONG,SOFT和WEAK三者其一。
默认是weak,让垃圾处理器去处理
</cacheModel>
<cacheModel type="LRU">
<flushInterval hours="24"/>
<flushOnExecute statement="insertProduct"/>
<flushOnExecute statement="updateProduct"/>
<flushOnExecute statement="deleteProduct"/>
<property name=”size” value=http://blog.soso.com/qz.q/”1000” /> //缓冲区大小
</cacheModel>
<cacheModel type="FIFO">
<flushInterval hours="24"/>
<flushOnExecute statement="insertProduct"/>
<flushOnExecute statement="updateProduct"/>
<flushOnExecute statement="deleteProduct"/>
<property name=”size” value=http://blog.soso.com/qz.q/”1000” />
</cacheModel>
<cacheModel type="OSCACHE">
<flushInterval hours="24"/>
<flushOnExecute statement="insertProduct"/>
<flushOnExecute statement="updateProduct"/>
<flushOnExecute statement="deleteProduct"/>
</cacheModel>
实际用法
Xml代码
<select id=”getProductList” cacheModel=”productCache”>
select * from PRODUCT where PRD_CAT_ID = #value#
</select>
在实际项目中运用时学习吧