Yii Framework Official Guide Series 31 - Caching: Page Caching

黄舟
Release: 2023-03-05 18:24:02
Original
977 people have browsed it



#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'),
        ),
    );
}
Copy after login

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)!


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!