If the access volume is millions or tens of millions, it will put a lot of pressure on the database or server. Through caching, the load on the server and database will be greatly reduced. For example, we divide the Data Reading Process into three layers: the first is the access layer, the first is the cache layer, and the third is the database layer. If there is no cache layer, the access layer reads data directly from the database layer. After the cache is set, the accessed data is not read directly at the database layer, but read from the cache layer. Let's make a simple comparison. Suppose a page can be accessed 1 million times in an hour. If the news page has millions or tens of millions of visits without caching, it puts a lot of pressure on the database or server. By caching, the load on the server and database is greatly reduced. Let us divide the Data Reading Process into three layers: the first is the access layer, the first is the cache layer, and the third is the database access layer. If there is no cache layer, the access layer reads data directly from the database access layer. After the cache is set, the access layer no longer reads data directly from the database access layer, but reads data from the cache layer.
Let's make a simple comparison. Assume that a page can be accessed 1 million times in an hour. If the page is accessed every time, the database is read directly before compilation, the page is repeatedly generated 1 million times in an hour. If the page is periodically cached for 10 minutes, that is, the cached data is generated every 10 minutes, within an hour, the server load will only be generated six times. The two methods have a one-to-one ratio and the effect is obvious. The pressure ratio of the two methods is more than ten thousand times different from that of the server load, the cache technology will make the website load more efficient during peak hours.
Thinkphp has many caching methods, such as File, Apachenote, Apc, Eaccelerator, Memcache, Shmop, Sqlite, Db, Redis, and Xcache. Now let's talk about File caching.
Thinkphp cache file configuration
Home is a front-end project created by me. Find the cache configuration file in Home \ Conf \ config. php and configure it as follows: