---
title: "[置顶] ibatis缓存"
author: "bd2007"
date: "2011-08-05T12:30:11Z"
tags: []
categories: ["企业架构"]
slug: "ibatis"
draft: false
lastmod: "2011-08-05T12:30:11Z"
id: 1140867
url: "https://bd2007.iteye.com/blog/1140867"
---

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秒之后刷新缓存的目的.