---
title: "ibatis缓存"
author: "learnmore"
date: "2008-09-04T11:20:46Z"
tags: []
categories: ["企业架构"]
slug: "ibatis"
draft: false
lastmod: "2008-09-04T11:20:46Z"
id: 236741
url: "https://learnmore.iteye.com/blog/236741"
---

1.首先在sqlmapconfig.xml中加入
<settings
    cacheModelsEnabled="true"
    enhancementEnabled="true"
        />
2.在sql.xml中加入
<cacheModel   id="hotwordCache"   readOnly="true" type="LRU" serialize="true">
<!--when the data has changed we flush the cache-->
<flushInterval seconds="60"/> ---如果想要在60秒后刷新缓存,必须把type设    为"LRU"
<flushOnExecute statement="inserthotword"/>----当进行增,删,改的时候刷新缓存
<flushOnExecute statement="hotworddel"/>
<property name="size" value="1000" />
 <property name="reference-type" value="WEAK" />
</cacheModel> 

3.我开始type配的属性为"MEMORY",每次数据库的操作都是直接反应出来,没有经过缓存,后来把type改为"LRU"才能实现从缓存中取数据,60秒之后刷新缓存的目的.