Using cache in CActiveDataProvider

You are viewing revision #1 of this wiki article.
This is the latest version of this article.

First param in CActiveDataProvider could be a string with model name or instance of class. So, you may use CActiveRecord::cache() for cache, but you need set third param to 2, because you should cache 2 queries: counting and get data.

Don't forget to use dependecy for cache invalidate.

$dependecy = new CDbCacheDependency('SELECT MAX(update_time) FROM {{post}}')

CActiveDataProvider(Post::model()->cache($duration, $dependecy, 2), array ( 
    'criteria' => array ( 
        'condition' => 'status = 1',
        'order' => 'DESC create_time',
    ) 
    'pagination' => array ( 
        'pageSize' => 20, 
    ) 
));