MyBatis二级缓存开启之后并没有效果,求助。
config.xml已开启
<setting name="cacheEnabled" value="true"/>
mapper.xml 已开启
<cache ></cache>
select语句
<select id="getById" resultType="User" useCache="true">
select * from m_user where id=#{id}
</select>
测试语句
public void testTwo() {
int begin,end;
SqlSession session1=SessionHelper.getSession();
UserMapper uMapper1=session1.getMapper(UserMapper.class);
begin=(int) System.currentTimeMillis();
User user1=uMapper1.getById(1);
end=(int) System.currentTimeMillis();
int x1=end-begin;
System.out.println("------------>"+user1.toString());
session1.close();
SqlSession session2=SessionHelper.getSession();
UserMapper uMapper2=session2.getMapper(UserMapper.class);
begin=(int) System.currentTimeMillis();
User user2=uMapper2.getById(1);
int x2=begin-end;
System.out.println("------------>"+user2.toString());
System.out.println(x1+"间隔事件对比"+x2);
session2.close();
}
log输出
DEBUG - Openning JDBC Connection
DEBUG - Created connection 31209237.
DEBUG - ooo Using Connection [com.mysql.cj.jdbc.ConnectionImpl@1dc3715]
DEBUG - ==> Preparing: select * from m_user where id=?
DEBUG - ==> Parameters: 1(Integer)
------------>id:1 username:update password:test
DEBUG - Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@1dc3715]
DEBUG - Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@1dc3715]
DEBUG - Returned connection 31209237 to pool.
DEBUG - Find JAR URL: file:/E:/EclipseEEWorkspace/MyBatisPractice1/bin/com/clei/domain
DEBUG - Not a JAR: file:/E:/EclipseEEWorkspace/MyBatisPractice1/bin/com/clei/domain
DEBUG - Reader entry: Course.class
DEBUG - Reader entry: Husband.class
DEBUG - Reader entry: Student.class
DEBUG - Reader entry: User.class
DEBUG - Reader entry: Wife.class
DEBUG - Listing file:/E:/EclipseEEWorkspace/MyBatisPractice1/bin/com/clei/domain
DEBUG - Find JAR URL: file:/E:/EclipseEEWorkspace/MyBatisPractice1/bin/com/clei/domain/Course.class
DEBUG - Cache Hit Ratio [com.clei.mapper.UserMapper]: 0.0
这还有一大段没复制过来。
DEBUG - Openning JDBC Connection
DEBUG - Created connection 19037581.
DEBUG - ooo Using Connection [com.mysql.cj.jdbc.ConnectionImpl@1227d8d]
DEBUG - ==> Preparing: select * from m_user where id=?
DEBUG - ==> Parameters: 1(Integer)
------------>id:1 username:update password:test
390间隔事件对比78
DEBUG - Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@1227d8d]
DEBUG - Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@1227d8d]
DEBUG - Returned connection 19037581 to pool.
<setting name="cacheEnabled" value="true"/>
mapper.xml 已开启
<cache ></cache>
select语句
<select id="getById" resultType="User" useCache="true">
select * from m_user where id=#{id}
</select>
测试语句
public void testTwo() {
int begin,end;
SqlSession session1=SessionHelper.getSession();
UserMapper uMapper1=session1.getMapper(UserMapper.class);
begin=(int) System.currentTimeMillis();
User user1=uMapper1.getById(1);
end=(int) System.currentTimeMillis();
int x1=end-begin;
System.out.println("------------>"+user1.toString());
session1.close();
SqlSession session2=SessionHelper.getSession();
UserMapper uMapper2=session2.getMapper(UserMapper.class);
begin=(int) System.currentTimeMillis();
User user2=uMapper2.getById(1);
int x2=begin-end;
System.out.println("------------>"+user2.toString());
System.out.println(x1+"间隔事件对比"+x2);
session2.close();
}
log输出
DEBUG - Openning JDBC Connection
DEBUG - Created connection 31209237.
DEBUG - ooo Using Connection [com.mysql.cj.jdbc.ConnectionImpl@1dc3715]
DEBUG - ==> Preparing: select * from m_user where id=?
DEBUG - ==> Parameters: 1(Integer)
------------>id:1 username:update password:test
DEBUG - Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@1dc3715]
DEBUG - Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@1dc3715]
DEBUG - Returned connection 31209237 to pool.
DEBUG - Find JAR URL: file:/E:/EclipseEEWorkspace/MyBatisPractice1/bin/com/clei/domain
DEBUG - Not a JAR: file:/E:/EclipseEEWorkspace/MyBatisPractice1/bin/com/clei/domain
DEBUG - Reader entry: Course.class
DEBUG - Reader entry: Husband.class
DEBUG - Reader entry: Student.class
DEBUG - Reader entry: User.class
DEBUG - Reader entry: Wife.class
DEBUG - Listing file:/E:/EclipseEEWorkspace/MyBatisPractice1/bin/com/clei/domain
DEBUG - Find JAR URL: file:/E:/EclipseEEWorkspace/MyBatisPractice1/bin/com/clei/domain/Course.class
DEBUG - Cache Hit Ratio [com.clei.mapper.UserMapper]: 0.0
这还有一大段没复制过来。
DEBUG - Openning JDBC Connection
DEBUG - Created connection 19037581.
DEBUG - ooo Using Connection [com.mysql.cj.jdbc.ConnectionImpl@1227d8d]
DEBUG - ==> Preparing: select * from m_user where id=?
DEBUG - ==> Parameters: 1(Integer)
------------>id:1 username:update password:test
390间隔事件对比78
DEBUG - Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@1227d8d]
DEBUG - Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@1227d8d]
DEBUG - Returned connection 19037581 to pool.
...全文
相关推荐
mybatis一级缓存和二级缓存简单示例
配套博客内容,mybatis一级缓存和二级缓存简单示例,供初学童鞋予以参考。 博客地址 https://blog.csdn.net/magi1201/article/details/85524712
深入理解MyBatis中的一级缓存与二级缓存
主要给大家深入的介绍了关于MyBatis中一级缓存与二级缓存的相关资料,文中详细介绍MyBatis中一级缓存与二级缓存的工作原理及使用,对大家具有一定的参考性学习价值,需要的朋友们下面来一起看看吧。
MyBatis开启二级缓存实现过程解析
主要介绍了MyBatis开启二级缓存实现过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
Mybatis如何通过注解开启使用二级缓存
主要介绍了Mybatis基于注解开启使用二级缓存,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
Mybatis-plus基于redis实现二级缓存过程解析
主要介绍了Mybatis-plus基于redis实现二级缓存过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下


Web 开发
