@cacheable缓存
6666666666666666666666
5555555555555555
44444444444444444444444444
333333333333333333333333333333
22222222222222222222222222222222
11111111111111111111111111111111111
1、引入依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency>
2、添加使用@Cacheable注解
@Cacheable(cacheNames={"menu"}) public List<String> getMenuList(){ System.out.println("只有第一次被调用"); return Arrays.asList("java","C++","PHP"); }
3、调用结果
@Cacheable时序图
缓存@Cacheable
SpringBoot对缓存的一个控制: 1、引入依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> 2、使用注解: @Cacheable(cacheNames={"menu"}) public List<String> getMenuList(){ System.out.println("看看是不是只有第一次被调用"); return Arrays.asList("java","C++","PHP"); }