生活随笔
收集整理的這篇文章主要介紹了
[mybatis]缓存_一级缓存_一级缓存失效的四种情况
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
@Testpublic void test05() throws IOException {SqlSessionFactory sqlSessionFactory
= getSqlSessionFactory();SqlSession sqlSession01
= sqlSessionFactory
.openSession();try{EmployeeMapper mapper01
= sqlSession01
.getMapper(EmployeeMapper.class);Employee emp01
= mapper01
.getEmpById(1);System.out
.println(emp01
);SqlSession sqlSession02
= sqlSessionFactory
.openSession();EmployeeMapper mapper02
= sqlSession02
.getMapper(EmployeeMapper.class);Employee emp02
= mapper02
.getEmpById(1);System.out
.println(emp02
);System.out
.println(emp01
==emp02
);sqlSession02
.close();}finally {sqlSession01
.close();}}
- 2.sqlSession相同,查詢(xún)條件不同
@Testpublic void test05() throws IOException {SqlSessionFactory sqlSessionFactory
= getSqlSessionFactory();SqlSession sqlSession01
= sqlSessionFactory
.openSession();try{EmployeeMapper mapper01
= sqlSession01
.getMapper(EmployeeMapper.class);Employee emp01
= mapper01
.getEmpById(1);System.out
.println(emp01
);
Employee emp02
= mapper01
.getEmpById(2);System.out
.println(emp02
);System.out
.println(emp01
==emp02
);}finally {sqlSession01
.close();}}
- 3.sqlSession相同,兩次查詢(xún)之間執(zhí)行了增刪改操作(這次增刪改可能對(duì)當(dāng)前數(shù)據(jù)有影響)
@Testpublic void test05() throws IOException {SqlSessionFactory sqlSessionFactory
= getSqlSessionFactory();SqlSession sqlSession01
= sqlSessionFactory
.openSession();try{EmployeeMapper mapper01
= sqlSession01
.getMapper(EmployeeMapper.class);Employee emp01
= mapper01
.getEmpById(1);System.out
.println(emp01
);
mapper01
.addEmp(new Employee(null,"testCache","cache","1"));System.out
.println("數(shù)據(jù)添加成功");Employee emp02
= mapper01
.getEmpById(2);System.out
.println(emp02
);System.out
.println(emp01
==emp02
);}finally {sqlSession01
.close();}}
- 4.sqlSession相同,手動(dòng)清除了一級(jí)緩存(緩存清空)
@Testpublic void test05() throws IOException {SqlSessionFactory sqlSessionFactory
= getSqlSessionFactory();SqlSession sqlSession01
= sqlSessionFactory
.openSession();try{EmployeeMapper mapper01
= sqlSession01
.getMapper(EmployeeMapper.class);Employee emp01
= mapper01
.getEmpById(1);System.out
.println(emp01
);
sqlSession01
.clearCache();Employee emp02
= mapper01
.getEmpById(2);System.out
.println(emp02
);System.out
.println(emp01
==emp02
);}finally {sqlSession01
.close();}}
總結(jié)
以上是生活随笔為你收集整理的[mybatis]缓存_一级缓存_一级缓存失效的四种情况的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。