布莱克 2017-08-07 17:31:33 1918次浏览 1条回复 0 0 0

1.png

怎么将下面的缓存做成,一个缓存存放两条数据???

  • 回复于 2017-08-07 18:09 举报
    public function actionIndex()
    {
        $this->view->title='外汇_外汇交易_外汇交易平台';
        $cache_key='Cache_Index_All';
        $data = Yii::$app->cache->get($cache_key);
        if(!$data){
            $rows = WebAds::find()->where(['display' => '1'])->all();
            $res = WebAnalystArticle::find()->orderBy('id desc')->limit(3)->all();
            Yii::$app->cache->set($cache_key,['rows'=>$rows,'res'=>$res],7200);
        }else{
            $rows=$data['rows'];
            $res=$data['res'];
        }
        return $this->render('index',['rows'=>$rows,'res'=> $res ]);
    }
    
您需要登录后才可以回复。登录 | 立即注册