In most cases, our site uses a database as a container for site data storage. When you execute an SQL query, the typical process is to connect database, prepare SQL query, send query to database, get database return results, and close the database connection. However, some of the data in the database is completely static or less frequent, and the cache system can be stored in a faster storage system by caching the results of the SQL query, thus avoiding the frequent operation of the database and greatly improving the program execution time, and the cached query results allow you to process it later.
Universally used PHP caching technology
Data Caching for PHP cache technology:
In this case, the data cache refers to the database query cache, each time the page is accessed, the corresponding cache data will be detected, if not, connect to the database, get the data, and the query results are serialized and saved to the file, the same query results are obtained directly from the cache file.
PHP Cache Technology Page Cache:
Each time you visit the page, will detect the corresponding cache page file exists, if not exist, connect to the database, get data, display the page and generate the cache page file at the same time, so the next visit to the page file will play a role. (the template engine and some common caching classes on the Web typically have this feature)
Memory Cache of PHP cache technology:
Not in the introduction, not to be discussed in this article, just briefly mention:
Memcached is a high-performance, distributed memory object caching system for reducing database load and increasing access speed in dynamic applications.
Dbcached is a distributed key-value database memory cache system based on Memcached and Nmdb.
Although the above cache technology can be a good solution to the problem of frequently querying the database, but its shortcomings in the data is not timeliness, below I give me in the project commonly used methods:
PHP Cache Technology Time-triggered cache:
Check that the file exists and that the timestamp is less than the expiration time of the setting, and if the timestamp of the file modification is greater than the current timestamp minus the expiration timestamp, then cache is used, otherwise the cache is updated.
Set time does not determine whether the data to be updated, over the set time and then update the cache. The above is only suitable for use when the timeliness requirements are not high, otherwise please see below.
The content of PHP cache technology triggers the cache:
Forces the cache to be updated when data is inserted or updated.
Here we can see that when there is a lot of data that needs to be updated frequently, the last involves disk read and write operations. How do I fix it? In my daily projects, I usually do not cache all the content, but rather cache some of the infrequently changed content to solve. However, in the case of heavy load, it is best to use shared memory as a caching system.
The PHP cache may be a bit of a solution here, but the downside is that because each request still has to be parsed by PHP, the efficiency problem is more severe in the case of a heavy load, in which case the static cache may be used.
Static caching of PHP cache technology
The static cache is referred to as the HTML cache, the HTML cache is generally not necessary to determine whether the data to be updated, because usually in the context of using HTML is often a page that does not change content frequently. Update the data when the HTML is also forced to update it.
The above describes the cad2008 installation instructions for the use of PHP caching technology, including the cad2008 installation instructions, I hope that the PHP tutorial interested in a friend to help.