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
sql

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

相关:ibatis sqlMapConfig settings 中属性用法性能

相关文章
相关标签/搜索