• iBATIS缓存cacheModel属性浅析


    iBATIS缓存cacheModel属性的应用使得在Mapped Statement中缓存常用的数据,那么本文将会给你介绍iBATIS缓存cacheModel属性的信息。

    AD:2013云计算架构师峰会课程资料下载

    iBATIS缓存模型可以在Mapped Statement中使用,在内存中缓存常用的数据。属性cacheModel 定义查询mapped statement 的缓存。每一个查询mapped statement 可以使用不同或相同的cacheModel。以下给出个例子:

    1. ﹤cacheModel id="product-cache" imlementation="LRU"﹥   
    2.  ﹤flushInterval hours="24"/﹥   
    3.  ﹤flushOnExecute statement="insertProduct"/﹥   
    4.  ﹤flushOnExecute statement="updateProduct"/﹥   
    5.  ﹤flushOnExecute statement="deleteProduct"/﹥   
    6.  ﹤property name="size" value="1000" /﹥   
    7. ﹤/cacheModel﹥   
    8. ﹤statement id="getProductList" parameterClass="int" cacheModel="product-cache"﹥   
    9.   select * from PRODUCT where PRD_CAT_ID = #value#   
    10. ﹤/statement﹥ 

    上面例子中,“getProductList”的缓存使用 WEAK 引用类型,每 24 小时刷新一次,或当更新的操作发生时刷新。 

    Cache Model使用插件方式来支持不同的缓存算法。它的实现在 cacheModel 的用 type属性来指定(如上所示)。指定的实现类必须实现 CacheController接口,或是下面 4个别名中的其中之一。Cache Model 实现的其他配置参数通过 cacheModel的 property元素来设置。目前包括以下的 4 个实现:

    ◆"MEMORY” (com.ibatis.db.sqlmap.cache.memory.MemoryCacheController) 。MEMORY cache 实现使用 reference 类型来管理 cache 的行为。垃圾收集器可以根据 reference类型判断是否要回收 cache 中的数据。MEMORY实现适用于没有统一的对象重用模式的应用,或内存不足的应用。

    ◆“LRU” (com.ibatis.db.sqlmap.cache.lru.LruCacheController) 。LRU Cache 实现用“近期最少使用”原则来确定如何从 Cache 中清除对象。当 Cache溢出时,最近最少使用的对象将被从 Cache 中清除。使用这种方法,如果一个特定的对象总是被使用,它将保留在 Cache 中,而且被清除的可能性最小。对于在较长的期间内,某些用户经常使用某些特定对象的情况(例如,在 PaginatedList 和常用的查询关键字结果集中翻页) ,LRU Cache 是一个不错的选择。

    ◆“FIFO” (com.ibatis.db.sqlmap.cache.fifo.FifoCacheController) 。FIFO Cache 实现用“先进先出”原则来确定如何从 Cache 中清除对象。当 Cache 溢出时,最先进入 Cache 的对象将从 Cache 中清除。对于短时间内持续引用特定的查询而后很可能不再使用的情况,FIFO Cache 是很好的选择。

    ◆“OSCACHE” (com.ibatis.db.sqlmap.cache.oscache.OSCacheController)  。OSCACHE Cache 实现是OSCache2.0缓存引擎的一个 Plugin。它具有高度的可配置性,分布式,高度的灵活性。

    iBATIS缓存cacheModel属性的情况就向你介绍到这里,是不是对于iBATIS缓存方面的应用有所了解了呢?

    http://developer.51cto.com/art/200907/137450.htm

    【编辑推荐】

    1. Hibernate与iBATIS的较量浅析
    2. iBATIS实例创建的五大步浅析
    3. iBATIS with MapBean应用浅析
    4. iBATIS接口应用的浅析
    5. Oracle下iBATIS XML配置浅析
  • 相关阅读:
    线段树
    数据结构<三> 队列
    数据结构<二>双向链表
    数据结构<一>单链表
    扩展欧几里德算法
    90 个 node.js 扩展模块,我们疯了
    nodejs的查询构造器
    express的路由配置优化
    express路由方案
    Redis学习笔记~目录
  • 原文地址:https://www.cnblogs.com/sand-tiny/p/3520865.html
Copyright © 2020-2023  润新知