1、常见的缓存有那些?
> MyBatis一级缓存、
> MyBatis二级缓存、
> 本地缓存:单节点
> 分布式Redis缓存:多节点
> 前端sessionStorage缓存:会话缓存
> 前端localStorage缓存:前端本地缓存
2、MyBatis一级缓存
MyBatis一级缓存默认是开启的。
在Spring Boot中需要添加@Transactional事务注解才能生效。
2.1、我们先来演示正常的查询情况:
// 搜索所有的火车车次
@Override
public List<TrainQueryResp> trainAll() {
List<Train> trainList = selectAllTrain();
LOG.info("查询了。。。");
trainList = selectAllTrain();
trainList = selectAllTrain();
// 使用hutool工具类将 List<Train> trainList 转换成List<TrainQueryResp>返回给前端
return BeanUtil.copyToList(trainList, TrainQueryResp.class);
}
<