Yii Framework official guide series 31-cache: page cache

Source: Internet
Author: User
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 )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.