Caching ActiveDataProvider

How correctly cache results of ActiveDataProvider for GridView for large tables?

Gii generates code like:




public function search($params)

{

    $query = Post::find();


    $dataProvider = new ActiveDataProvider([

        'query' => $query,

    ]);


    $this->load($params);


    if (!$this->validate()) {

        return $dataProvider;

    }


    // grid filtering conditions

    $query->andFilterWhere([

        'id' => $this->id,

        'status' => $this->status,

        'type' => $this->type,

        'public_date' => $this->public_date,

    ]);


    $query->andFilterWhere(['like', 'title', $this->title])

        ->andFilterWhere(['like', 'full_content', $this->full_content])


    return $dataProvider;

}



Thanks!

The following SO topic may be helpful.

http://stackoverflow.com/questions/30889772/yii2-how-to-cache-active-data-provider

Also I’m interedted in this extension … CacheDataProvider extending ActiveDataProvider.

And I think we can consider using FragmentCache that caches the page fragment where the GridView is rendered, rather than caching the query results using QueryCache. But I’m not sure what to use as the key and the variations for the cache content.