Cache Activedataprovider

Hi,

I’d like to cache data for ActiveDataProvider, but with no success. My code:




$data =\yii::$app->db->cache(function(){

  return Model::find();

});

	

$dataProvider = new ActiveDataProvider([

  'query' => $data

]);



Debugger always shows 2 queries, one for counting records, second for quering data.

How to store AR in Yii2 cache?

Thanks

The query is made by the dataprovider, not by ModeL::find() so you have to put the dataprovider in the cache function and also make sure it does the querying directly by calling the prepare() method.