Page caching refers to caching the content of the entire page. The page cache can occur in different places. For example, by selecting an appropriate page header, the browser on the client may cache the webpage for a limited time. Web applications can also be stored in...
Page caching refers to caching the content of the entire page. The page cache can occur in different places. For example, by selecting an appropriate page header, the browser on the client may cache the webpage for a limited time. Web applications can also store Web content in the cache. In this section, we focus on the next approach.
Page cache can be seen as a special case of fragment caching. Because the webpage content is often generated through the application layout, if we simply call beginCache () and endCache () in the layout, it will not work normally. This is because the layout in the CController: render () method is loaded after the page content is generated.
To cache the entire page, we should skip the action that generates the page content. We can use COutputCache as the action filter to complete this task. The following code demonstrates how to configure a cache filter:
public function filters(){ return array( array( 'COutputCache', 'duration'=>100, 'varyByParam'=>array('id'), ), );}
The above filter configuration will apply the filter to all actions in the controller. We may restrict it in one or several actions by using the plug-in operator. For more details, see the filter.
Tip:We can use COutputCache as a filter because it inherits from CFilterWidget, which means it is a tool and a filter. In fact, the widget works in a similar way as a filter: the tool widget (filter) is executed before the content in the action is executed and ends after execution.
The above is the Yii Framework official guide series 31-cache: page cache content. For more information, see PHP Chinese website (www.php1.cn )!