回顾商城项目时发现最热商品即使下架了还是能够查询到,本以为是缓存问题,通过redis可视化工具进行查看,发现与缓存无关,是代码中忘记加入条件查询所致,
更改前
@GetMapping("/list/hot") @Cacheable(value = "hot10Goods",condition = "true") public Result getHotGoodsList(){ Page p = new Page(1,10); QueryWrapper q = new QueryWrapper(); q.orderByDesc("sale_count"); return goodsService.getListForPage(p,q,GoodsMapper.class); }
更改后
@GetMapping("/list/hot") @Cacheable(value = "hot10Goods",condition = "true") public Result getHotGoodsList(){ Page p = new Page(1,10); QueryWrapper q = new QueryWrapper(); q.eq("is_on_sale",1); q.orderByDesc("sale_count"); return goodsService.getListForPage(p,q,GoodsMapper.class); }