Page caching refers to caching the contents of an entire page. The page cache can occur in different places. For example, by selecting the appropriate page header, the client's browser may cache Web browsing 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. Because Web content is often generated by applying layouts, if we simply call Begincache () and Endcache () in the layout, it will not work correctly. This is because the layout is loaded in the Ccontroller::render () method after the page content is generated.
If you want to cache the entire page, we should skip the execution of the action that generated the page content. We can use Coutputcache as an action filter to accomplish this task. The following code shows how to configure a cache filter:
Public Function Filters () { return Array ( array ( ' Coutputcache ', ' duration ' =>100, ' VaryByParam ' =>array (' id '),) , );}
The filter configuration above makes the filter suitable for all actions in the controller. We may limit it in one or several actions by using the plug-in operator. More details can be seen in the filter.
Tip: we can use Coutputcache as a filter because it inherits from Cfilterwidget, which means it's a tool (widget) and a filter. In fact, widgets work in a very similar way to filters: The tool widget (filter filters) executes before the content in the action action executes and ends after execution.
The above is the official Yii Framework Guide Series 31--cache: page cache content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!