This method is very common in CMS systems, such as dedecms;; The common implementation method is to use the output cache: ob _ start () * * * * * code to be run * * * * $ content = ob _ get _ contents (); * * * * Write the cached content to the html file * * * * ob _ end _ clean (); Second, data caching, as the name implies, is a way to cache data; For example, when requesting commodity information in a shopping center with a commodity id, data including store information and commodity information will be obtained. At this time, these data can be cached in a php file, and the file name contains the product id to build a unique tag; Next time someone wants to check this product, first check the information in this file directly, without going to the database. In fact, the cache file caches php arrays and the like; This method is applied to Ecmall mall system. Third, query caching In fact, this is an idea with data caching, that is, caching according to query statements; Cache the data obtained by the query in a file, and the next time you encounter the same query, you will directly call out the data from this file first, and you will not check the database again; However, the cache file name here may need to establish a unique label according to the query statement; Caching according to time changes means that you need to set a valid time for caching files. Within this valid time, the same access will first get the contents of the cache file, but if the set cache time is exceeded, you need to get the data from the database again and generate the latest cache file. For example, I set the homepage of our mall to be updated every 2 hours.
Fourth, cache the part of the page. In this way, the parts of a page that do not change frequently are statically cached, while the blocks that change frequently are not cached, and finally assembled and displayed together; It can be implemented in a way similar to ob_get_contents, or a page fragment caching strategy such as ESI can be used to cache the relatively static fragment part of a dynamic page.
This method can be used in, for example, the product page in the mall; 5. The opcode cache first parses the php code into a token, then compiles it into an opcode code, and finally executes the opcode code and returns the result; Therefore, for the same php file, you can cache its opcode code the first time you run it, and the next time you execute this page, you can directly find the cached opcode code and directly execute the last step without intermediate steps.
Well-known ones are XCache, TurckMMCache, PHPAccelerator and so on.
6. Cache according to content changes. This is not an independent caching technology and needs to be combined. That is, when the database content is modified, the cache file is updated immediately; For example, in a shopping mall with a large flow of people, there are many commodities, and the list of commodities is bound to be relatively large, and the pressure on this table is also relatively heavy; We can cache the product display page; When the merchant modifies the product information in the background, click Save and we will update the cache file at the same time; Then, when the buyer accesses this product information, he actually asks a static page, and he doesn't need to visit the database again; Imagine that if the product page is not cached, then every time you visit a product, you have to query it in the database. If 65,438+10,000 people browse products online, the pressure on the server will be great; Seven, the memory cache mentioned this, maybe the first thing that everyone thinks of is Memcached;; Memcached is a high-performance distributed memory cache server.
The general purpose is to reduce the number of database visits by caching database query results, so as to improve the speed and scalability of dynamic Web applications.
Cache the information that needs to be cached in the system memory, and take it out directly from the memory when it needs to be obtained; The more common way is the key _> value model; Connect($memcachehost, $memcacheport) or die ("could not connect"); $ memcache-& gt; Set('key',' cache content'); $ get = $ memcache-& gt; get($ key); //Get information? & gt VIII. apache Cache Module Cache is not allowed after apache is installed.
Chongqing IT training/thinks that if external cache or squid server needs web acceleration, it needs to be set in htttpd.conf, provided that mod_cache module is activated when apache is installed.