Cahing is one of the best tools to improve performance and thereby create faster load times and an increased user experience for your users. There are many standardized cahing mechanisms you can implement, but Yii actually gives it’d developers a high level implemntation, so you don’t even have to worry about the cahcing system itself. You can simply apply cahing to pages, or wherever you need it. So check out the example on page cahing from The Definite Guide to Yii here:
Page caching can be considered as a special case of fragment caching. Because the content of a page is often generated by applying a layout to a view, it will not work if we simply call beginCache() and endCache() in the layout. The reason is because the layout is applied within the CController::render() method AFTER the content view is evaluated.
To cache a whole page, we should skip the execution of the action generating the page content. We can use COutputCache as an action filter to accomplish this task. The following code shows how we configure the cache filter:
public function filters() { return array( array( 'COutputCache', 'duration'=>100, 'varyByParam'=>array('id'), ), ); }
The above filter configuration would make the filter to be applied to all actions in the controller. We may limit it to one or a few actions only by using the plus operator. More details can be found in filter.
No comments yet (leave a comment)