已经将一级缓存设置为了 statement ,关闭了二级缓存
mybatis:
configuration:
cache-enabled: false
local-cache-scope: statement
测试
@GetMapping("/test")
@Transactional
public User test() throws InterruptedException {
User user = userMapper.selectById(1);
System.out.println(user);
TimeUnit.SECONDS.sleep(5);
User user2 = userMapper.selectById(1);
System.out.println(user2);
return user2;
}
疑问
2022-01-01 19:33:18.320 DEBUG 49182 --- [nio-8000-exec-4] com.ding.mapper.UserMapper.selectById : ==> Preparing: SELECT * FROM `user` WHERE id = ?
2022-01-01 19:33:18.321 DEBUG 49182 --- [nio-8000-exec-4] com.ding.mapper.UserMapper.selectById : ==> Parameters: 1(Integer)
2022-01-01 19:33:18.322 DEBUG 49182 --- [nio-8000-exec-4] com.ding.mapper.UserMapper.selectById : <== Total: 1
User(id=1, username=test, password=222, phone=)
2022-01-01 19:33:23.327 DEBUG 49182 --- [nio-8000-exec-4] com.ding.mapper.UserMapper.selectById : ==> Preparing: SELECT * FROM `user` WHERE id = ?
2022-01-01 19:33:23.327 DEBUG 49182 --- [nio-8000-exec-4] com.ding.mapper.UserMapper.selectById : ==> Parameters: 1(Integer)
2022-01-01 19:33:23.328 DEBUG 49182 --- [nio-8000-exec-4] com.ding.mapper.UserMapper.selectById : <== Total: 0
User(id=1, username=test, password=222, phone=)
日志是打印了两遍 sql ,在休眠的 5 秒前我已经在数据库把这条数据清空了,但是第二次执行的结果返回的还是和第一次一样
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.