mybatis 二级缓存不推荐使用
一 mybatis的缓存使用。
大体就是首先根据你的sqlid,参数的信息自己算出一个key值,然后你查询的时候,会先把这个key值去缓存中找看有没有value,如果有,直接返回出来,就不查询db了。如果没有,那么查询db,然后将key,value保存到缓存中,以便下次使用。
1.1mybatis的一级缓存是基于sqlsession为生命周期的
当你这个session没有了,缓存就没有了,其次当你sql执行!isselect语句的时候,缓存也会被直接全部清理掉以保证数据一致性。
public int update(MappedStatement ms, Object parameter) throws SQLException {
ErrorContext.instance().resource(ms.getResource()).activity("executing an update").object(ms.getId());
if (closed) throw new ExecutorException("Executor was closed.");
//清理缓存
clearLocalCache();
return doUpdate(ms, parameter);
}