iBATIS缓存不会在给定语句上刷新

时间:2009-03-19 07:42:36

标签: caching ibatis

我正在使用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语句,也不会刷新缓存。它维护在插入/更新/删除之前选择的数据!

请让我知道我哪里出错。

1 个答案:

答案 0 :(得分:0)

尝试将缓存设置为readOnly =“false” - 来自文档:

  

该框架支持只读   和读/写缓存。只读   缓存在所有用户之间共享   因此提供更好的性能   效益。但是,从一个对象读取   只读缓存不应该是   改性。相反,一个新的对象应该   从数据库中读取(或者   用于更新的读/写缓存。在   另一方面,如果有意图   使用对象进行检索和   修改,读/写缓存是   推荐(即要求)。用一个   只读缓存,设置readOnly =“true”   在缓存模型元素上。用一个   读/写缓存,设置   readOnly的=”假”。默认是   只读(true)。

相关问题