Summary of various methods of PHP Cache Technology and php Cache

Source: Internet
Author: User

Summary of various methods of PHP Cache Technology and php Cache
The data cache mentioned here refers to the PHP cache mechanism for database query. when accessing the page every time, the system checks whether the cache data exists. If the cache data does not exist, it connects to the database to obtain the data, serialize the query results and save them to the file. Later, the same query results will be obtained directly from the cache table or file.1. General Cache Technology: 

Data Cache: The data cache here refers to the PHP cache mechanism for database queries. Each time you access the page, it first checks whether the cache data exists. If it does not exist, it connects to the database, obtain the data and serialize the query results and save them to the file. The same query results will be obtained directly from the cache table or file.

The most widely used example is the Discuz search function. The result ID is cached in a table and the table is searched in the cache next time when the same keywords are searched.

For example, when multiple tables are joined, an array generated in the appendix is saved to a field in the master table. If necessary, the array is decomposed, the advantage is read-only tables. The disadvantage is that two data synchronization steps are many more steps, and the database is always the bottleneck. Changing the disk speed is the key point.

2. 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 PHP cache mechanism classes on the Internet usually have this function)

3. cache triggered by Time: 

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.

4. Content-triggered cache:

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

5. Static cache: 

The static cache mentioned here refers to static, which directly generates HTML, XML, and other text files. It is re-generated once when there is an update. This is suitable for pages that do not change much.


The above content is a code-level solution. The following content is a server-side cache solution. Non-code-level solutions can only be achieved through cooperation among multiple parties.

6. Memory Cache:

Memcached is a high-performance, distributed memory object PHP cache mechanism system that reduces database loads in dynamic applications and improves access speed.

7. php Buffer: 

There are eaccelerator, apc, phpa, and xcache. You don't need to talk about this. You can search for a bunch of them and read them by yourself. If you know what it is, OK.

8. MYSQL cache: 

This is not code-level. The classic database uses this method. See the following running time, such as 0.09xxx.

9. Reverse Proxy-based Web Cache: 

For example, Nginx, SQUID, mod_proxy (apache2 and above are also divided into mod_proxy and mod_cache)

10. DNS round robin:

BIND is an open-source DNS server software, which is too big to be mentioned. You can search for it by yourself.
I know that chinacache and other major sites are doing this. Simply put, they are multiple servers and cache the same page or file on different servers, it is automatically resolved to the relevant server by North and South.

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.