tags:

views:

866

answers:

2

Hi,

I am using iBatis for my database interaction. Lately I am trying to improve performance of some static data fetches by configuring caching. The chache got configured and worked properly however the problem is in flushing of cache data whenever any insert/update/delete happens to that data. I did following configuration for category table,

<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>

Now the problem is that even if any of insertCategory / updateCategory / deleteCategory statement is executed, the cache does not get flushed. It maintains the data whatver was selected prior to insert / update / delete !

Please let me know where I am going wrong.

A: 

Hi jatanp,

did you find a solution for the problem?

Regards, Christian

Christian Junk
A: 

Try setting your cache to readOnly="false" -- From the documentation:

The framework supports both read-only and read/write caches. Read-only caches are shared among all users and therefore offer greater performance benefit. However, objects read from a read-only cache should not be modified. Instead, a new object should be read from the database (or a read/write cache) for updating. On the other hand, if there is an intention to use objects for retrieval and modification, a read/write cache is recommended (i.e. required). To use a read-only cache, set readOnly=”true” on the cache model element. To use a read/write cache, set readOnly=”false”. The default is read-only (true).

rcurts