public List<WeixinMenu> getList() {
        List<WeixinMenu> weixinMenuList= (List<WeixinMenu>) redisTemplate.opsForValue().get("weixinMenuList");    //先在缓存中查询一遍
        if (weixinMenuList==null){
            synchronized (this){
                weixinMenuList= (List<WeixinMenu>) redisTemplate.opsForValue().get("weixinMenuList");   //如果缓存空了,在线程加锁的情况下再从缓存中查询一次
                if (weixinMenuList==null){              
                    weixinMenuList=WeixinMenuMng.getList();                 //还是没有查到,就从数据库查询,查询后放到缓存中
                    redisTemplate.opsForValue().set("weixinMenuList",weixinMenuList);
                }
            }
        }
        return weixinMenuList;
    }

  

相关文章:

  • 2021-08-21
  • 2021-08-30
  • 2021-05-13
  • 2023-01-30
  • 2021-07-29
  • 2022-12-23
  • 2021-08-22
  • 2022-01-27
猜你喜欢
  • 2021-06-30
  • 2021-05-29
  • 2021-10-03
  • 2021-09-09
  • 2022-01-25
  • 2021-10-22
  • 2021-11-09
相关资源
相似解决方案