模型关联预载入不支持缓存预载入怎么办?

浏览:401 发布日期:2018/08/13 分类:求助交流 关键字: 模型 关联预载入 缓存
模型可以支持存入缓存,但是模型关联的时候就管用了,可能以为惰性加载的原因的,在模板里调用关联模型的时候数据的时候,才执行了sql语句。怎么直接加到缓存里呢,提高速度。    public function index(){


      // 查询最新的聊天信息

      if (!cache('talk_new')) {
        # code...

        dump('no cache');
     
            $talk_new = Data::with('foot,watermelon,user,dataSelf,likesList')
                    ->withCount('likeslist')
                    ->order('id', 'desc')
                    ->limit(10)
                    ->cache(60)
                    ->select();

             cache('talk_new', $talk_new, 60);

      }




           $this->assign('talk_new', cache('talk_new'));

       return view();

    }
最佳答案
评论( 相关
后面还有条评论,点击查看>>