IBatisNet1.5 — 對應檔–Cache Models

來源:互聯網
上載者:User
        Cache也是經常討論的一個話題之一,在我們系統開發的過程中,總會存在著這樣一類資料,它們更新頻率很低,然而使用的頻率卻非常之高。為了提高系統效能,我們通常將此類資料裝入緩衝。Ibatisnet 也有自己的緩衝系統。
        MappedStatement的查詢結果集可以根據cacheModel的值來確定它是否被裝入緩衝以及如何裝入緩衝。而Cache Model也是在設定檔中事先定義好的。具體的定義方式如下:<cacheModel id="employee-cache" implementation="LRU" readOnly="true" serialize="false">
  <flushInterval hours="24"/>
  <flushOnExecute  statement="insertEmployee"/>
  <flushOnExecute  statement="updateEmployee"/>
  <flushOnExecute  statement="deleteEmployee"/>
  <property name="CacheSize" value="100"/>
</cacheModel>

上面的cache model配置好之後,它會建立一個名為"employee-cache"的緩衝執行個體,implementation表示它的實現規則是LRU,即:Leaste Recently Used。ibatisnet還有MEMORY,FIFO幾種緩衝的模式。readOnly的值說明緩衝是唯讀還是可讀寫的,如果readOnly為true,緩衝就是唯讀,false為可讀寫。serialize指示緩衝是在整個Application中有效還是僅作用於當前的Session。flushInterval的值表示緩衝的有效期間,上面的配置中則表示改緩衝每24小時清空一次,當然有效期間還可以用minutes, seconds or milliseconds來表示。flushOnExecute表示緩衝將在執行了什麼操作時被清空,上面的配置中表示該緩衝在執行insertEmployee or updateEmployee or deleteEmployee時被清空。CacheSize表示緩衝的最大條目,當超過這個值的時候就會按照implementation中定義的規則來清除相應的條目,上面配置中則表示當緩衝的條目超過100時,則移出最近最少使用的條目。當我們配置好cacheModel之後就可以在statement中使用了,如下:

<statement id="EmployeeList" cacheModel="employee-cache">
  select * from Employee
</statement>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.