ibatis中使用缓存

简单在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 中属性用法

posted @ 2017-09-17 22:55  jack_ou  阅读(1125)  评论(0编辑  收藏  举报