概述
spring-cache可以用来进行缓存穿透、缓存击穿、缓存雪崩
demo
yml:
pom:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
@Cacheable:缓存到redis中,@CacheEvict:删除一条缓存
@GetMapping("one")
@Cacheable(cacheNames = "area",key = "#id")
public Stock one(@RequestParam Long id){
return iStockService.getById(id);
}
@GetMapping("removeStockCache")
@CacheEvict(cacheNames = "area",key = "#id" )
public void removeStockCache(@RequestParam Long id){
}