IBatis Caching Memory

  • santhosh kiran
    santhosh kiran

    Hi ,
      Iam new to Ibatis.I want to use Caching. I have gone through the manual :

    <cacheModel id="staticcodes-cache" type="MEMORY">
        <flushInterval hours="24"/>
        <property name="reference-type"    value="STRONG"/>

    <statement id="getCodesFromDB" resultClass="com.pbg.mware.mfiles.client.data.CodeDetail" parameterClass="java.lang.Integer" cacheModel="staticcodes-cache">
              TABLE_ID as id ,
              CODE_VAL as codeVal ,
              CODE_VAL_DESCR as  codeValDescr,
              USER_ID as createdBy ,
              CODE_ACTV_FLG as  codeActvFlg,
              LOCK_DTE_TME as lastUpdate
        WHERE TABLE_ID=#value#

    When i executed the Query , everytime ,Generated SQL  run in  Database and returns result set values.

    But I heard by using caching for the first time SQL runs in Database and returns me the values ,and everytime we get from the memory as
    Cache Model is
    <cacheModel id="staticcodes-cache" type="MEMORY">

    and property value ="STRONG"

    TestCase :
    1.   I ran the Query first time ,through Ibatis and  got result set values.

    2. Next time , I inserted a row into the Database using Rapid Sql( from database console) by executing Query without using Ibatis .

    3. then second time , I ran the Query using Ibatis  , but Iam getting the Values which i inserted externally , so Caching is not working.

    Help me out , and where iam doing wrong.

    Thanks in advance.


    • Kris Jenkins
      Kris Jenkins

      First thing to check is that in your sql-map-config.xml, cacheModelsEnabled="true".


    • santhosh kiran
      santhosh kiran

      Thanks Kris

    • Larry Meadors
      Larry Meadors

      Gentle reminder - you should have posted this to the apache list instead. :)

  • Thanks, This was really useful. I have another question on caching.

    Now my sample application picks data from cache data and If I Manually update the data in the database it doesn't reflect in my application. my question revolves around this now

    I have cached the data in my application to increase the performance so now the data is being picked up from cache. later I did some manual update on database from back end using SQL Script and I want that data to reflect immediately on my application.

    i.e., the application should pick up new data from database if and only if the data in the database is changed using *SQL Script*, If the data is not changed then it should continue using the data in the cache.