mybatis整合ehcache
2024-08-30 10:56:10
知识点: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>
最新文章
- sftp上传 - 待完
- ngxtop:在命令行实时监控 Nginx 的神器
- URAL 1549 Another Japanese Puzzle(构造)
- iOS--为视图添加阴影
- poj2255 (二叉树遍历)
- poj 1523 SPF(tarjan求割点)
- 64位CentOS 6.0下搭建LAMP环境
- 报错utf-8错误
- ionic3 小记录
- x = x &;(x-1)
- win10下Redis安装
- hdoj5754
- Spring Advice
- Blender 简单齿轮驱动
- WebGIS实现在线要素编辑之ArcGIS Server 发布Feature Service 过程解析
- nginx报错整理
- write file to stroage trigger kernel warning
- Code Blocks中配置OpenGL
- UVA.10325 The Lottery (组合数学 容斥原理 二进制枚举)
- day15 web框架和Django基础
热门文章
- datasnap 授权验证DSAuthenticationManager方法应用
- B-、B+、B*树
- python3 用requests 保存网页以及BeautifulSoup保存图片,并且在本地可以正常显示文章的内容和图片
- Selenium Page Object(PO)设计模式
- 在vue中使用express-mock搭建mock服务
- import MySQLdb 与 import mysql 有什么区别?
- 在debian9上安装mongodb
- GoDaddy用支付宝付款时出现我们无法处理这笔交易,请查看您的付款信息并重试。
- Mysql 压力测试工具 mysqlslap
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) B. Code For 1