MyBatis缓存的概念

Terwer 后端开发 MyBatis评论187字数 331阅读1分6秒阅读模式

缓存回顾

缓存就是内存中的数据,常常来自对数据库查询结果的保存。文章源自浅海拾贝-https://blog.terwergreen.com/the-concept-of-mybatis-cache-nfdfh.html

使用缓存可以避免频繁与数据库交互,进而提高响应速度。文章源自浅海拾贝-https://blog.terwergreen.com/the-concept-of-mybatis-cache-nfdfh.html

MyBatis 对缓存的支持

MyBatis 也提供了对缓存的支持,分为 一级缓存二级缓存。可以用下面的图来理解:文章源自浅海拾贝-https://blog.terwergreen.com/the-concept-of-mybatis-cache-nfdfh.html

MyBatis缓存的概念文章源自浅海拾贝-https://blog.terwergreen.com/the-concept-of-mybatis-cache-nfdfh.html

  1. 一级缓存是 SqlSession 级别的缓存。在操作数据库时,需要构造 SqlSession 对象,在对象中有一个 HashMap 的数据结构用于存储缓存数据。不同的 SqlSession 之间缓存的数据区域(HashMap)是不同的。
  2. 二级缓存是 Mapper 级别的缓存。多个 SqlSession 操作同一个 Mapper 的 sql 语句,多个 SqlSession 可以共用二级缓存,二级缓存是跨 SqlSession 的。

文章更新历史
2022-09-06 feat:初稿 文章源自浅海拾贝-https://blog.terwergreen.com/the-concept-of-mybatis-cache-nfdfh.html

文章源自浅海拾贝-https://blog.terwergreen.com/the-concept-of-mybatis-cache-nfdfh.html
相关文章
  • 扫码加我微信
  • 验证消息请输入:来自你的博客
  • weinxin
  • 我的微信公众号
  • 微信扫一扫与我交流吧
  • weinxin
Terwer
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: