1. 一级缓存 与 二级缓存
参考:https://www.cnblogs.com/winclpt/articles/7511672.html
1.1 定义:
1.2 代码中应用:
1.2.1 一级缓存:
默认开启的
原理:是sqlsession级别的缓存,存放在内存中
1.2.2 二级缓存:
原理:
需要配置
配置2处: 注意配置文件的位置 及 设置缓存的时间有效性
<!--开启二级缓存-->
<setting name="cacheEnabled" value="true"/>
<!--
eviction LRU
flushInterval缓存时间,以毫秒为单位
size缓存大小
readOnly如果为false的话,缓存对象必须是可序列化的-->
<cache eviction="LRU"
type="org.apache.ibatis.cache.impl.PerpetualCache"
flushInterval="60000"
size="1024"
readOnly="true"/>
测试二级缓存:
准备:开启二级缓存 ,系统配置日志
测试过程:
第一次:直接查询数据库了