---
title: "cacheModel"
author: "yinxiangbing"
date: "2009-02-02T11:15:46Z"
tags: ["Cache"]
slug: "cachemodel"
draft: false
lastmod: "2009-02-02T11:15:46Z"
id: 321848
url: "https://yinxiangbing.iteye.com/blog/321848"
---

cacheModel的属性值等于指定的cacheModel元素的name属性值。属性cacheModel定义查询mapped statement的缓存。每一个查询mapped statement可以使用不同或相同的cacheModel。详细讨论见后面的章节，以下只给出个例子。  
&lt;cacheModel id="product-cache" imlementation="LRU"&gt;  
&lt;flushInterval hours="24"/&gt;  
&lt;flushOnExecute statement="insertProduct"/&gt;  
&lt;flushOnExecute statement="updateProduct"/&gt;  
&lt;flushOnExecute statement="deleteProduct"/&gt;  
&lt;property name=”size” value=”1000” /&gt;  
&lt;/cacheModel&gt;  
&lt;statement id=”getProductList” parameterClass=”int” cacheModel=”product-cache”&gt;  
select * from PRODUCT where PRD\_CAT\_ID = #value#

 

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