User单表查询(数据量11029条)
使用Spring自带缓存
开启方法
- 主启动类加
@EnableCaching
- Service层方法添加注解
@Cacheable(value = "userList")
最终效果
理论上讲查询数据耗时应该和MySQL执行查询语句耗时相差不大在50ms左右
第一次耗时较长可能是因为需要创建连接等操作。
代码
pom
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId