Yii Framework Official Guide Series 31--cache: page Cache

Source: Internet
Author: User
Tags yii



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

  • 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.