zoukankan      html  css  js  c++  java
  • IBatisNet1.5 映射文件Cache Models

            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>

  • 相关阅读:
    redis
    魔法方法
    vue
    bbs技术总结
    Linux
    爬虫
    路飞项目
    Django-rest framework框架
    Django框架
    WEB
  • 原文地址:https://www.cnblogs.com/pw/p/568911.html
Copyright © 2011-2022 走看看