PHP Cache technology instructions

Source: Internet
Author: User
PHP Cache technology is widely used. some people may not know much about this technology. now we will give you a detailed introduction to the related application skills of PHP Cache technology. In most cases, our website uses databases as the container for storing site data. When you execute an SQL query, the typical process is: connect to the database-> prepare an SQL query-> Send a query to the database-> Get the database return result-> Close the database connection. However, some data in the database is completely static or infrequently changed. the cache system caches the SQL query results to a faster storage system for storage, this avoids frequent database operations and greatly increases the program execution time, and caches the query results for later processing.

Widely used PHP Cache technology

Data Caching in PHP Cache technology:

The data cache mentioned here refers to the database query cache. each time you access the page, it first checks whether the cache data exists. if it does not exist, it connects to the database to obtain the data, the query results are serialized and saved to the file. the same query results will be obtained directly from the cache file.

PHP Cache technology-Page cache:

Each time you access the page, the system first checks whether the corresponding cached page file exists. if it does not exist, it connects to the database to obtain data, displays the page, and generates cache page files at the same time, in this way, the page file will play a role in the next visit. (The template engine and some common cache classes on the Internet usually have this function)

Memory cache of PHP Cache technology:

I will not introduce it here. it is not discussed in this article. I just want to mention it briefly:

Memcached is a high-performance, distributed memory object cache system that reduces database loads in Dynamic Applications and improves access speeds.

Dbcached is a distributed key-value database memory cache system based on Memcached and NMDB.

Although the above caching technology can effectively solve the problem of frequent database queries, its disadvantage is that the data is not time-sensitive. below I will provide a method that is commonly used in projects:

PHP Cache technology-time-triggered cache:

Check whether the file exists and the timestamp is earlier than the set expiration time. if the modified timestamp of the file is greater than the current timestamp minus the expiration timestamp, use the cache; otherwise, update the cache.

During the set time, the system does not judge whether the data is to be updated. after the set time, the system updates the cache. The above is applicable only when the requirements for timeliness are not high. otherwise, please refer to the following.

Content-triggered caching in PHP Cache technology:

When data is inserted or updated, the cache is forcibly updated.

Here we can see that when a large amount of data frequently needs to be updated, disk read/write operations will be involved in the end. How can this problem be solved? In my daily projects, I usually do not cache all content, but cache some of the content that is not changed frequently. However, in the case of heavy load, it is best to use the shared memory as a cache system.

Here, PHP Cache may be a solution, but its disadvantage is that, because every request still needs to be parsed by PHP, the efficiency problem is still serious under heavy load conditions, in this case, static cache may be used.

PHP Cache technology-static cache

The static cache here refers to the HTML cache. The HTML cache generally does not need to judge whether the data is to be updated, because the HTML cache usually does not change the content frequently. When the data is updated, you can force the HTML to be updated.
Related 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.