在启动类中加入注解
不需要导入包,其他包已经依赖了
@SpringBootApplication
//启用redis缓存注解
@EnableCaching
public class SellApplication {
public static void main(String[] args) {
SpringApplication.run(SellApplication.class, args);
}
}
查询加入缓存
@GetMapping("/product/list")
//吧返回的对象存入到redis,第二次访问redis缓存中的内容
@Cacheable(cacheNames = "product" ,key = "123")
public Result goodsList(){
删除缓存 实现更新缓存的效果
@GetMapping("/index")
@CacheEvict(cacheNames = "product" , key = "123")
public ModelAndView indexProduct(String gid)