MyBatis二级缓存开启之后并没有效果,求助。

「已注销」 「已注销」 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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.





...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
「已注销」
Web 开发 81,108 成员 341,721 内容