---
title: "ibatis Tips 之 cacheModel"
author: "xulongfa"
date: "2009-07-18T16:58:45Z"
tags: ["Blog", "Cache", "iBATIS"]
slug: "ibatis-tips-cachemodel"
draft: false
lastmod: "2009-07-18T20:33:24Z"
id: 428592
url: "https://xulongfa.iteye.com/blog/428592"
---

cacheModel的属性值等于指定的cacheModel元素的name属性值。属性cacheModel定义查询mapped statement的缓存。每一个查询mapped statement可以使用不同或相同的cacheModel。

```
<cacheModel id="product-cache"  imlementation="LRU">
      <flushInterval hours="24"/>
      <flushOnExecute  statement="insertProduct"/>
      <flushOnExecute  statement="updateProduct"/>
      <flushOnExecute  statement="deleteProduct"/>
     <property name=”size” value=”1000” />
</cacheModel>
<statement  id=”getProductList”  parameterClass=”int” 
                    cacheModel=”product-cache”>
        select * from PRODUCT where PRD_CAT_ID = #value#
</statement>
```

 

上面例子中，“getProductList”的缓存使用WEAK引用类型，每24小时刷新一次，或当更新的操作发生时刷新。

 

下面的内容转自javaeye 作者:lggege  引用地址:[http://lggege.iteye.com/blog/216615](http://lggege.iteye.com/blog/216615)