php cache is a running mode that is compiled and run, including PHP compilation cache and PHP data cache; the characteristics of php cache are: 1. Time-triggered cache, check whether the file exists and timestamp Less than the set expiration time; 2. Content-triggered caching, which forces the PHP caching mechanism to be updated when data is inserted or updated; 3. Static caching, which directly generates text files such as HTML or XML, and regenerates them when there are updates.
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.
What does php cache specifically mean?
PHP caching technology is an interpreted language that compiles and runs at the same time, including PHP compilation cache and PHP data cache.
PHP cache, the advantage of this operating mode is that program modification is very convenient, but the operating efficiency is very low. The PHP compilation cache has been improved to deal with this situation, so that the PHP language can cache the compilation results of the program as long as it is run once. In this way, every subsequent run does not need to be compiled again, which greatly improves the running speed of PHP. PHP data caching is used to cache data processing in the actual development of PHP. The two main directions are: caching database data and caching PHP template data.
PHP cache type
1. Database data cache technology:
Data cache: The data cache mentioned here refers to the database query PHP cache mechanism , every time a page is accessed, it will first detect whether the corresponding cached data exists. If it does not exist, it will connect to the database, obtain the data, and serialize the query results and save them to a file. In the future, the same query results will be directly obtained from the cache. obtained from a 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. and memcache technology.
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.
Commonly used database data caching technologies are:
1. Serialization (serialization) cache
2. JSON cache
3. XML cache
4.Array cache
2. Page cache:
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 cache 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 PHP caching mechanism classes on the Internet usually have this function, such as smarty templates and thinkphp framework)
Technical features
1. 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.
2. Content-triggered caching:
Forcibly update the PHP cache mechanism when data is inserted or updated.
3. 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, which is suitable for applications that do not change much. The page, I won’t talk about it here. .
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What exactly does php caching mean?. For more information, please follow other related articles on the PHP Chinese website!