Springboot 默认cache

1:Springboot 默认缓存为ConcurrentMapCacheManager(spring-context)

2:再启动类上开启缓存

@SpringBootApplication //相当于上边几个的集合
//@EnableScheduling//开启定时任务注解
@EnableCaching// 开启缓存,需要显示的指定
public class Application {
public static void main(String[] args) {

SpringApplication.run(Application.class, args);


}
}

3:spring 3.1以上支持注解使用缓存

@Cacheable(value="student",key="1")表示添加数据到缓存中,缓存名称为student,缓存key为1。 请求触发后先去检查缓存中有没有数据有的话直接返回没有则查询数据库
@CacheEvict(value="student",key="1")表示从缓存people中删除key为1的数据   
@CachePut(value="student",key="1")表示吧查询的结果添加到缓存中

不检查缓存中是否有数据,直接把查询结果放到缓存中,一般不经常用,用cacheable较多

具体使用查看https://www.cnblogs.com/fashflying/p/6908028.html

猜你喜欢

转载自www.cnblogs.com/coderdxj/p/9133404.html
今日推荐