0

我正在使用 iBatis 进行数据库交互。最近我试图通过配置缓存来提高一些静态数据获取的性能。chache 已配置并正常工作,但是问题在于每当对该数据进行任何插入/更新/删除时都会刷新缓存数据。我为类别表做了以下配置,

<cacheModel  type="LRU" id="categoryCache"  readOnly="true" serialize="false">
    <flushOnExecute statement="insertCategory"/>
    <flushOnExecute statement="updateCategory"/>
    <flushOnExecute statement="deleteCategory"/>
    <property name="size" value="1000"/>
</cacheModel>

<insert id="insertCategory"
    parameterClass="com.uniplas.entity.master.beans.CategoryVO">
    insert into categories (code, description)
    values(#code:VARCHAR#,#description:VARCHAR#)
</insert>

<update id="updateCategory"
    parameterClass="com.uniplas.entity.master.beans.CategoryVO">
    update categories set description=#description:VARCHAR# where code=#code:VARCHAR#
</update>

<delete id="deleteCategory"
    parameterClass="com.uniplas.entity.master.beans.CategoryVO">
    delete from categories where code=#code:VARCHAR#
</delete>

<select id="selectCategory" resultMap="categoryResult"
    parameterClass="java.util.Map" cacheModel="categoryCache">
    select * from categories where 1=1
    <dynamic>
        <isNotEmpty property="categoryVO.code">
            and code like #categoryVO.code:VARCHAR#
        </isNotEmpty>
        <isNotEmpty property="categoryVO.description">
            and description like
            #categoryVO.description:VARCHAR#
        </isNotEmpty>
        <isNotEmpty property="orderBy">
            order by $orderBy$
        </isNotEmpty>

    </dynamic>
</select>

现在的问题是,即使执行了任何 insertCategory / updateCategory / deleteCategory 语句,缓存也不会被刷新。它维护在插入/更新/删除之前选择的数据!

请让我知道我哪里出错了。

4

1 回答 1

0

尝试将缓存设置为 readOnly="false" - 从文档中:

该框架支持只读和读/写缓存。只读缓存在所有用户之间共享,因此可以提供更大的性能优势。但是,不应修改从只读缓存读取的对象。相反,应该从数据库(或读/写缓存)中读取一个新对象以进行更新。另一方面,如果打算使用对象进行检索和修改,则建议使用读/写缓存(即必需)。要使用只读缓存,请在缓存模型元素上设置 readOnly=”true”。要使用读/写缓存,请设置 readOnly=”false”。默认值为只读 (true)。

于 2009-11-19T22:25:09.370 回答