Using cache in CActiveDataProvider

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, 
    ) 
));
17 0
11 followers
Viewed: 28 617 times
Version: 1.1
Category: Tips
Written by: Stamm
Last updated by: Stamm
Created on: Sep 12, 2011
Last updated: 13 years ago
Update Article

Revisions

View all history

Related Articles