Home > Article > Backend Development > Yii Framework Official Guide Series 31 - Caching: Page Caching
#Page caching refers to caching the content of the entire page. Page caching can occur in different places. For example, by selecting appropriate page headers, the client's browser may cache a web page for a limited time. The web application itself can also store web page content in the cache. In this section, we focus on the latter approach.
Page caching can be seen as a special case of fragment caching. Since web page content is often generated by applying layout, if we simply call beginCache() and endCache() in the layout, it will not work properly. This is because the layout is loaded in the CController::render() method after the page content is generated.
If we want to cache the entire page, we should skip the execution of actions that generate web content. We can use COutputCache as an action filter to accomplish 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 cause the filter to be applied to the controller all actions in . We may limit it to one or a few actions by using plugin operators. More details can be found in Filters.
Tip: We can use COutputCache as a filter because it inherits from CFilterWidget, which means it is a tool (widget) and a filter. In fact, widgets work very similarly to filters: tool widgets (filters) are executed before the content in the action is executed and end after execution.
The above is the Yii Framework Official Guide Series 31 - Caching: Page Caching For more related content, please pay attention to the PHP Chinese website (www.php.cn)!