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.