一级缓存默认开启,和SqlSession生命周期相同,可以存储经常查询和修改的数据
二级缓存默认关闭,和SqlSessionFactory生命周期相同,可以存储经常查询不经常修改的数据
二级缓存存放的数据量比一级缓存大
二级缓存的开启:
在mapper关系映射配置文件中
添加<cache>标签
<cache readOnly="true"></cache>
<select>标签的useCache="true"
<select id="queryGoodsById" resultType="goods" parameterType="long" useCache="true">
select
<include refid="goodsColums"/>
from Goods
where t_id = #{value}
</select>