springboot项目Redis项目,注解缓存,删除缓存

在启动类中加入注解
不需要导入包,其他包已经依赖了

@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)
发布了62 篇原创文章 · 获赞 21 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_40618664/article/details/98961238