知识点:mybatis整合encache缓存框架,缓存从数据库中,查询的数据,不使用mybatis自带的二级缓存

补充:github上Mybatis Ehcache 适配器包说明地址:http://www.mybatis.org/ehcache-cache/index.html

(1)向pom.xm中导入缓存依赖包,和适配器包

<!--ehcache依赖-->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</dependency> <!--Mybatis Ehcache 适配器包-->
<dependency>
<groupId>org.mybatis.caches</groupId>
<artifactId>mybatis-ehcache</artifactId>
<version>1.1.0</version>
</dependency> (2)向mapper.xml中,添加配置
<cache type="org.mybatis.caches.ehcache.EhcacheCache"></cache> //调用Mybatis Ehcache 适配器包中的接口,实现缓存功能
//补充:其他mapper.xml中,再次使用缓存,直接使用
<!--引用缓存,namespace:指定和哪个名称空间下的缓存一样-->
<cache-ref namespace="com.xxMapper"></cache-ref>
<!--<cache eviction="FIFO" flushInterval="60000" readOnly="false" size="1024"></cache>-->//区别mybatis自带的二级缓存配置

(3)加入ehcache.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<ehcache updateCheck="true" monitoring="autodetect" dynamicConfig="true"> <!-- name:缓存名称
eternal:缓存中对象是否为永久的,如果是,超时设置将被忽略,对象从不过期。
maxElementsInMemory:内存缓存最大个数
maxEntriesLocalDisk:当maxElementsInMemory已达到最大值时,写入磁盘
timeToIdleSeconds:缓存对象失效前的闲置时间 默认值为:0 闲置时间无穷大
timeToLiveSeconds:缓存对象最大的有效时间(TTL) 默认值为:0 闲置时间无穷大
diskExpiryThreadIntervalSeconds::磁盘失效线程运行时间间隔,默认是120秒
memoryStoreEvictionPolicy:当达到maxElementsInMemory限制时,Ehcache将会根据指定的策略去清理内存。
默认策略是LRU(最近最少使用)。你可以设置为FIFO(先进先出)或是LFU(较少使用)
clearOnFlush:内存数量最大时是否清除
--> <!-- 磁盘缓存位置 -->
    <diskStore path="E:/nishuai/cache"/>
    <!-- 默认缓存 -->
<defaultCache
maxEntriesLocalHeap="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
maxEntriesLocalDisk="10000000"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"/> </ehcache>
 
 
 

最新文章

  1. sftp上传 - 待完
  2. ngxtop:在命令行实时监控 Nginx 的神器
  3. URAL 1549 Another Japanese Puzzle(构造)
  4. iOS--为视图添加阴影
  5. poj2255 (二叉树遍历)
  6. poj 1523 SPF(tarjan求割点)
  7. 64位CentOS 6.0下搭建LAMP环境
  8. 报错utf-8错误
  9. ionic3 小记录
  10. x = x &amp;(x-1)
  11. win10下Redis安装
  12. hdoj5754
  13. Spring Advice
  14. Blender 简单齿轮驱动
  15. WebGIS实现在线要素编辑之ArcGIS Server 发布Feature Service 过程解析
  16. nginx报错整理
  17. write file to stroage trigger kernel warning
  18. Code Blocks中配置OpenGL
  19. UVA.10325 The Lottery (组合数学 容斥原理 二进制枚举)
  20. day15 web框架和Django基础

热门文章

  1. datasnap 授权验证DSAuthenticationManager方法应用
  2. B-、B+、B*树
  3. python3 用requests 保存网页以及BeautifulSoup保存图片,并且在本地可以正常显示文章的内容和图片
  4. Selenium Page Object(PO)设计模式
  5. 在vue中使用express-mock搭建mock服务
  6. import MySQLdb 与 import mysql 有什么区别?
  7. 在debian9上安装mongodb
  8. GoDaddy用支付宝付款时出现我们无法处理这笔交易,请查看您的付款信息并重试。
  9. Mysql 压力测试工具 mysqlslap
  10. Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1