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,



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

        return $dataProvider;


    // grid filtering conditions


        '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;



The following SO topic may be helpful.

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.