Home > Article > Backend Development > Detailed explanation of caching technology under PHP
Common caching technology Data cache: The data cache mentioned here refers to the database query cache. Every time you access the page, it will first detect whether the corresponding cached data exists. If it does not exist, connect to the database, get the data, and put the query results. After serialization, save it to a file. In the future, the same query results will be obtained directly from the cache table or file. The most widely used example is the search function of Discuz, which caches the result ID into a table and searches the cache table first when searching for the same keyword next time. For a common method, when multiple tables are associated, generate an array and save the contents in the attached table to a field in the main table. When necessary, decompose the array. This has the advantage of only reading one table, but has two disadvantages. Data synchronization will take many more steps, and the database is always the bottleneck. Trading hard disk for speed is the key point in this. Page Caching: Every time a page is accessed, it will first detect whether the corresponding cached page file exists. If it does not exist, it will connect to the database, get the data, display the page and generate a cached page file at the same time, so that the page file will play a role the next time you visit. . (Template engines and some common cache classes on the Internet usually have this function) Time triggered cache: Check whether the file exists and the timestamp is less than the set expiration time. If the file modification timestamp is greater than the current timestamp minus the expiration timestamp, then use the cache, otherwise update the cache. Content triggered caching: Force the cache to be updated when data is inserted or updated. Static Cache: The static cache mentioned here refers to static, directly generating text files such as HTML or XML, and regenerating them when there are updates. It is suitable for pages that do not change much, so I won’t talk about it here. The above content is a code-level solution. I directly CP other frameworks and am too lazy to change. The content is almost the same. It is easy to do and can be used in several ways. However, the following content is a server-side caching solution. At the code level, it requires the cooperation of multiple parties to achieve it Memory Cache: Memcached is a high-performance, distributed memory object caching system used to reduce database load and improve access speed in dynamic applications. Here is an example of Memcached:
Example of reading library :
php buffer: There are eaccelerator, apc, phpa, xcache, let’s not talk about these. Search a bunch of them and see for yourself. If you know that there is such a thing, it’s OK MYSQL Cache: This is also considered non-code level. Classic databases use this method. Look at the running time below, it is 0.09xxx and so on. I am posting the part of my.ini modified by the guy in blue. The 2G MYISAM table can be around 0.05S. It is said that he modified it for almost a year Code copy box
Reverse proxy based web caching: Such as Nginx, SQUID, mod_proxy (apache2 and above are divided into mod_proxy and mod_cache) NGINX example
Example of mod_proxy:
For examples of SQUID, you can refer to here. DNS polling: BIND is an open source DNS server software. This is a big deal to mention. Just search it yourself and everyone knows that it exists. I know that some large websites such as chinacache do this. To put it simply, it is multi-server. The same page or file is cached on different servers and automatically parsed to the relevant server according to the north and south. |