Menu

IBatis Caching Memory

2004-11-19
2013-04-11
  • santhosh kiran

    santhosh kiran - 2004-11-19

    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"/>
      </cacheModel>
     

    <statement id="getCodesFromDB" resultClass="com.pbg.mware.mfiles.client.data.CodeDetail" parameterClass="java.lang.Integer" cacheModel="staticcodes-cache">
        SELECT
              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
        FROM
              COMMON..CODE_DETL
        WHERE TABLE_ID=#value#
      </statement>

    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.

    Santhosh.

     
    • Kris Jenkins

      Kris Jenkins - 2004-11-20

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

      Kris

       
    • santhosh kiran

      santhosh kiran - 2004-11-20

      Thanks Kris

       
    • Larry Meadors

      Larry Meadors - 2004-11-22

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

       
  • Display nameJagadeesh H Sadashiv

    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.

     

Log in to post a comment.