Learn about the caching of Yii (learn from the web---and "yii framework" have to tell the story-efficient article)

Source: Internet
Author: User
Tags call back

1. Delay loading of classes and mapping of tables
The first one is to implement the separate invocation of the class without having to start loading all the files. If you put it in the IF statement, you can load the class

The second graph is the implementation of class delay loading, mainly using the Spl_autoload_register function only when the program creates a new class, if the system determines that he does not exist, the function will be loaded once. Yii is also used by this idea.

The third and fourth graph, is Yii uses the class delay loading way, in the Yii entrance file index.php There, loads the yii.php file, then yii.php the file inside also uses the Spl_autoload_register function.

The fifth diagram, which is the use of the YII mapping table, is to attach an absolute path to the specified class so that it can be called to her, but this applies to frequently used classes.

2. Delay Loading of components
The first diagram is the load flow of the component, which is first instantiated by $app and then called in the controller. And in Yii. Only when a component is needed in the controller, this way to load the primary key, and Yii this method will call the __get () method to load the specified component, in this way, the delay load of the component

3. Cache additions and Deletions
The following methods will be able to achieve the data deletion and modification of the search,
PS: If it is repeated to increase the value of the key will not be effective

4. Set the expiration date and cache dependency of the data cache
When you set the cache time, just add a time to the function immediately after.

There are three kinds of dependencies, one is the dependency of the file, one is the dependence of the expression, the other is the dependence of the DB, the equivalent of a file or an expression or a db, and so on, the cache does not exist, if it is also called the key value of the cache information, it will return false.


5. Fragment Caching
The fragment cache is added by adding a $this->begincache (' data ') through the add-on layer, which then caches the data inside the div. Parameters can be used to set cache time, cache dependencies, and caching switches

6. Page Caching
Page caching, use behavior to execute before calling the index method and then use the configuration file to tell the browser to use the page cache. A call pagecache something to cache the page.

Comparison of the cached head and the not-cached head

7.http Cache
1) 304 means that the cached data will not be re-transmitted without modification. The last modified and ETag are the two tags to determine if the changes have been made.

Call is a method of HttpCache

2)
Using the Last-modified and ETag fields to determine if you need to increase the cache last-modified indicates that the last time the ETag was modified indicates whether the data has been modified. png

Judge LastModified and then judge the ETag. If two are different, they'll call back.

For the last modified and ETag display information inside the HTTP header protocol

3) implementation in the Code

The code for using the ETag and last modified is as follows.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Learn about the caching of Yii (learn from the web---and "yii framework" have to tell the story-efficient article)

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.