文章出處

簡單在ibatis中使用cache

  首先設置SqlMapConfig.xml中<settings/>節點的屬性cacheModelsEnabled="true"
  
  然后在具體sqlmap文件中書寫<cacheModel>
    <cacheModel id="product-cache" type="LRU"> 
      <flushInterval hours="24"/> 
      <flushOnExecute statement="insertProduct"/>
      <flushOnExecute statement="updateProduct"/> 
      <flushOnExecute statement="deleteProduct"/> 
      <property name="size" value="1000" /> 
    </cacheModel>
   
  最后給<select/>節點應用cache
    <select id="getAllProducts" cacheModel="product-cache">
      select * from PRODUCT
    </statement> 
    
復雜點的用法

  <cacheModel/>節點
  
    type="LRU"
      type屬性可以指定cache的類型,ibatis支持3種緩存:
        MEMORY     沒有統一的對象重用模式或內存不足的應用。
        LRU        經常使用的對象,這是性能最好的選擇。
        FIFO       在短時間內持續引用,而后很可能不再使用。
      也可以使用外部cache如:
        type="OSCACHE"
     
    readOnly="true"
      默認true時緩存效果最好,可以減少更新。
      
    serialize="false"
      默認false,設true可以提高整體應用的性能。
        serialize只能應用于實現了Serializable接口的對象,而且和lazyLoadingEnabled="true"屬性沖突。
        
    flushInterval
      自動刷新間隔時間。

    flushOnExecute
      在特定id的操作后,刷新cache,可選操作。

  手動刷新緩存
    [sqlmap].flushDataCache("product-cache")
      刷新cache當id="product-cache"
    [sqlmap].flushDataCache()
      刷新sqlmap內的所有cache

原文:http://blog.csdn.net/zzcv_/article/details/1956056

相關:ibatis sqlMapConfig settings 中屬性用法


文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()