自定义缓存 - ehcache
Ehcache是一种广泛使用的开源Java分布式缓存。主要面向通用缓存,Java EE和轻量级容器
- 导包
<!-- https://mvnrepository.com/artifact/org.mybatis.caches/mybatis-ehcache -->
<dependency>
<groupId>org.mybatis.caches</groupId>
<artifactId>mybatis-ehcache</artifactId>
<version>1.1.0</version>
</dependency>
- 在 Mapper.xml 中指定使用 ehcache 缓存实现
<!--在当前 Mapper.xml 中使用二级缓存-->
<cache type="org.mybatis.caches.ehcache.EhcacheCache"/>
- 在resource中定义配置文件 ehcache.xml
<?xml version="1.0" encoding="UTF-8" ?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false">
<!--
diskStore: 缓存路径, ehcache分为内存和磁盘两级, 此属性定义磁盘的缓存位置
参数: