Home > headlines > Several major PHP caching technologies that must be obtained

Several major PHP caching technologies that must be obtained

小云云
Release: 2017-11-04 16:45:43
Original
1664 people have browsed it

1. Full page static caching

That is to say, all pages are generated as HTML static pages. The static pages are directly accessed when users visit, without going through the PHP server parsing process. This method is more common in CMS systems, such as dedecms;

A more common implementation method is to use output caching:

Ob_start()

*** ***Code to run******

$content = Ob_get_contents();

****Write cached content to html file*****

Ob_end_clean();

2. Page partial caching

This method is to statically cache the parts of a page that do not change frequently, while frequently changing blocks are not cached. Caching, and finally assembled together for display; it can be implemented using a method similar to ob_get_contents, or you can use a page fragment caching strategy such as ESI to cache relatively static fragments in dynamic pages (ESI technology, please baidu, not detailed here).

This method can be used for example, on product pages in malls;

3. Data caching

As the name suggests, it is a way of caching data; for example, in a mall When a certain product information is requested using the product ID, data including store information, product information, etc. will be obtained. At this time, these data can be cached in a php file. The file name contains the product ID to create a unique identifier. ;The next time someone wants to view this product, first directly adjust the information in this file without querying the database; In fact, what is cached in the cache file is a php array;

In the Ecmall mall system This method is used;

4. Query caching

In fact, this is the same idea as data caching, which is to cache according to the query statement; cache the data obtained by the query in a file. The next time you encounter the same query, you will directly retrieve the data from this file instead of checking the database; however, the cache file name here may need to be uniquely identified based on the query statement;

Caching based on time changes

In fact, this is not a real caching method; the caching technologies 2, 3, and 4 above generally use time change judgment; that is, you need to set a valid cache file time, within this valid time, the same access will first fetch the contents of the cache file. However, if the set cache time is exceeded, the data needs to be obtained from the database again and the latest cache file will be produced; for example, I will The homepage is set to be updated every 2 hours;

5. Cache according to content changes

This is not an independent caching technology and needs to be used in combination; it means that when the database content is modified, it will be updated immediately Cache files;

For example, in a mall with a lot of traffic and a lot of products, the product table must be relatively large, and the pressure on this table is 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 the product information, he actually accesses a static page and does not need to access the database. ;

Just imagine, if the product page is not cached, then every time you access a product, you have to check the database. If 100,000 people browse the product online, the pressure on the server will be great;

6. Memory caching

When it comes to this, the first thing you may think of is Memcached; memcached is a high-performance distributed memory cache server. The general purpose of use is to reduce the number of database accesses by caching database query results to increase the speed and scalability of dynamic web applications.

It caches the information that needs to be cached into the system memory. When the information needs to be obtained, it is retrieved directly from the memory; the more commonly used method is the key–>value method;

$ memcachehost = '192.168.6.191';

$memcacheport = 11211;

$memcachelife = 60;

$memcache = new Memcache;

$memcache ->connect($memcachehost,$memcacheport) or die ("Could not connect");

$memcache->set('key','cached content');

$get = $memcache->get($key); //Get information

?>


##

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