cacheModel的属性值等于指定的cacheModel元素的name属性值。属性cacheModel定义查询mapped statement的缓存。每一个查询mapped statement可以使用不同或相同的cacheModel。
- <cacheModelid="product-cache"imlementation="LRU">
- <flushIntervalhours="24"/>
- <flushOnExecutestatement="insertProduct"/>
- <flushOnExecutestatement="updateProduct"/>
- <flushOnExecutestatement="deleteProduct"/>
- <propertyname=”size”value=”1000”/>
- </cacheModel>
- <statementid=”getProductList”parameterClass=”int”
- cacheModel=”product-cache”>
- select*fromPRODUCTwherePRD_CAT_ID=#value#
- </statement>
上面例子中,“getProductList”的缓存使用WEAK引用类型,每24小时刷新一次,或当更新的操作发生时刷新。
本文介绍MyBatis中如何通过cacheModel元素配置查询缓存。示例展示了使用LRU缓存实现方式,并设置缓存刷新间隔及在特定操作执行后刷新缓存的方法。

252

被折叠的 条评论
为什么被折叠?



