There are several types of php cache

青灯夜游
Release: 2023-03-14 16:54:02
Original
1801 people have browsed it

There are 5 types of PHP cache: 1. Data cache, that is, database query PHP cache mechanism; 2. Page cache; 3. Time-triggered cache; 4. Content-triggered cache, that is, when data is inserted or updated. , force the PHP cache mechanism to be updated; 5. Static cache.

There are several types of php cache

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

The standard process of a website or an application is to browse The server sends a request to the application server. The application server does some calculations and logical judgments before requesting the database. After receiving the request, the database returns the data to the application server after calculation. The application server calculates again and returns the data to the browser.

Then, as the complexity and concurrency of the web business increase, the application server performs more and more calculations and logical processing. However, the resources of the application server are limited, and the number of times the database accepts and processes requests per second It's also limited. In order to provide as much throughput as possible with limited resources, it is necessary to reduce the amount of calculation and shorten the request process (reduce network I/O or hard disk I/O). At this time, Cache is used

php cache type

1. Data cache:

Data cache: The data cache mentioned here refers to the database query PHP cache mechanism. 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 Serialize the query results and save them 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.

As 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. The advantage of this is that only one table can be read. , the disadvantage is that there will be many more steps to synchronize the two data. The database is always the bottleneck. Trading the hard disk for speed is the key point of this.

2. Page cache:

Every time you access a page, it will first detect whether the corresponding cached page file exists. If it does not exist, connect to the database and get Data, display the page and generate a cache page file at the same time, so that the page file will be effective the next time you visit. (Template engines and some common PHP caching mechanism classes on the Internet usually have this function)

3. Time-triggered cache:

Check whether the file exists and the timestamp is less than the setting The 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.

4. Content-triggered caching:

Forcibly update the PHP cache mechanism when data is inserted or updated.

5. Static cache:

The static cache mentioned here refers to static, directly generate text files such as HTML or XML, and regenerate them when there are updates. , suitable for pages that don’t change much, so I won’t talk about it here.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of There are several types of php cache. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template