缓存cacheModel

为了提高查询的效率,通常将查询的结果放到缓存中存放起来。在ibatis中实现缓存的方法是:在查询statement中指定cacheModel属性。cacheModel元素的配置:
[code]
<cacheModel id="product-cache" type="LRU" readOnly="true" serialize="false">
<flushInterval hours="24" />
<flushOnExecute statement="insertProduct" />
<flushOnExecute statement="updateProduct" />
<flushOnExecute statement="deleteProuct" />
<property name="cache-size" value="1000" />
</cacheModel>
[/code]
注:LRU----近期最少使用
flushInterval :每24小时刷新一次,一个cacheModel只能有一个该元素,也可以通过minutes,seconds或milliseconds来设定
下面属性的几个表明,当执行insertProduct,updateProduct,deleteProuct时,缓存也被刷新。
serialize属性是指缓存可读写。
type属性有:
[b]--->MEMORY:[/b]
[code]
<cacheModel id="product-cache" type="MEMORY" >
<flushInterval hours="24" />
<flushOnExecute statement="insertProduct" />
<flushOnExecute statement="updateProduct" />
<flushOnExecute statement="deleteProuct" />
<property name="reference-type" value="WEAK" />
</cacheModel>
[/code]
<property name="reference-type" value="WEAK" />
value值:
STRONG:可以确保查询结果数据一直保留在内存中,除非cache被刷新
SOFT:在查询结果对象数据不被使用,同时需要内存分配其他对象的情况下,SOFT类型将减少内存不足的可能性。然而这不是最具侵入性的reference类型,结果数据依然可能被清除
WEAK:缺省的,通常是最佳的。
[b]--->LRU:[/b]近期最少使用
[b]--->FIFO:[/b]先进先出
[code]
<cacheModel id="product-cache" type="FIFO" >
<flushInterval hours="24" />
<flushOnExecute statement="insertProduct" />
<flushOnExecute statement="updateProduct" />
<flushOnExecute statement="deleteProuct" />
<property name="cache-size" value="1000" />
</cacheModel>
[/code]
[b]--->OSCACHE:[/b]
[code]
<cacheModel id="product-cache" type="FIFO" >
<flushInterval hours="24" />
<flushOnExecute statement="insertProduct" />
<flushOnExecute statement="updateProduct" />
<flushOnExecute statement="deleteProuct" />
</cacheModel>
[/code]
参考:[url]http://www.opensymphony.com/oscache/[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值