美文网首页学习笔记
06[笔记] SpringBoot 删除Redis指定缓存

06[笔记] SpringBoot 删除Redis指定缓存

作者: 杨不易呀 | 来源:发表于2020-04-24 17:35 被阅读0次
/* ******************************************载入缓存开始************************************************** */
      
      
      /**
       * 保存部门信息
       * 获取缓存信息
       *
       * @param dept
       * @return
       */
      @CachePut(cacheNames = "top.yangbuyi.system.service.impl.DeptServiceImpl", key = "#result.id")
      @Override
      public Dept saveDept(Dept dept) {
            //  mq insert会返回一个 添加后的id
            this.deptMapper.insert(dept);
            log.info(dept.getTitle() + ",改信息已存入缓存");
            return dept;
      }
      
      /**
       * 修改部门
       * 获取缓存信息
       *
       * @param dept
       * @return
       */
      @CachePut(cacheNames = "top.yangbuyi.system.service.impl.DeptServiceImpl", key = "#result.id")
      @Override
      public Dept updateDept(Dept dept) {
            this.deptMapper.updateById(dept);
            log.info(dept.getTitle() + ",已修改缓存当中的信息");
            return dept;
      }
      
      /**
       * 重写 mq 方法  获取缓存信息
       *
       * @param id
       * @return
       */
      @Cacheable(cacheNames = "top.yangbuyi.system.service.impl.DeptServiceImpl", key = "#id")
      @Override
      public Dept getById(Serializable id) {
            log.info(id + ",已从缓存当中获取");
            return super.getById(id);
      }
      
      /**
       * 重写 mq 删除方法
       *
       * @param id
       * @return
       */
      @CacheEvict(cacheNames = "top.yangbuyi.system.service.impl.DeptServiceImpl", key = "#id")
      @Override
      public boolean removeById(Serializable id) {
            log.info(id + ":已将该信息从缓存当中删除");
            return super.removeById(id);
      }
      
      /* ******************************************载入缓存结束************************************************** */
      
      
      /* ******************************************清理全部缓存开始************************************************** */
      
      @Override
      @CacheEvict(value = "top.yangbuyi.system.service.impl.DeptServiceImpl", allEntries = true)
      public void clearAllRedisDB() {
            log.info("指定清理部门Redis缓存槽中的所有对象....");
      }
      /* ******************************************清理全部缓存结束************************************************** */

作者:杨不易
链接:https://www.jianshu.com/nb/45397607
来源:简书

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

相关文章

网友评论

    本文标题:06[笔记] SpringBoot 删除Redis指定缓存

    本文链接:https://www.haomeiwen.com/subject/yfxqwhtx.html