Springboot整合Mybatis二级缓存

上一篇 << 下一篇 >>>Mybatis常见面试题


1、mapper上注解二级缓存

@CacheNamespace(implementation = MybatisRedisCache.class)
public interface UserMapper {
}

2、启动类开启二级缓存

@SpringBootApplication
@MapperScan("cn.jarye.mapper")
@EnableCaching
public class App {
}

3、每次的调用,均会创建session和关闭session,所以是存在多个session的。

org.mybatis.spring.SqlSessionInterceptor implements InvocationHandler里面有sqlSession.commit(true);

将二级缓存临时数据保存到二级缓存中


推荐阅读:
<< << << << << << << << << <<

你可能感兴趣的:(Springboot整合Mybatis二级缓存)