Home>

That is, all the pages are generated into html static pages.Static pages that users visit directly,Instead of going through the php server parsing process.This way,More common in cms systems,For example, dedecms, the following is a summary of the php9 big cache technology through this article.

1. Full page static cache

That is, all the pages are generated into html static pages.Static pages that users visit directly,Instead of going through the php server parsing process.This way,More common in cms systems,Such as dedecms;

A more common implementation is to use output caching:

ob_start ()

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

$content=ob_get_contents ();

**** Write cache content to html file *****

ob_end_clean ();

Partial page caching

That way,Is to statically cache the infrequently changing parts of a page,And frequently changing blocks are not cached,Finally assembled together and displayed;It can be implemented in a way similar to ob_get_contents,You can also use a page fragment caching strategy like esi,It is used to cache the relatively static fragment part in dynamic pages (esi technology, please google, not explained here).

This method can be used for product pages, such as in a mall;

Data caching

As the name suggests,Is a way to cache data;For example, a product information in the mall,When requesting with product id,You will get data including store information, product information, etc.At this time, you can cache these data in a php file, the file name contains the product id to create a unique identifier;Next time someone wants to see this product,First of all, directly adjust the information in this file,No need to go to the database to query;in fact, the cache file is a PHP array or the like;

This method is used in ecmall mall system;

4, query cache

In fact, this is an idea with data caching.Is cached according to the query;Cache the query data in a file,The next time the same query is encountered,Just transfer data directly from this file,Will not check the database again;However, the cache file name here may need to be uniquely identified based on the query statement;

Cache by time change

In fact, this one is not a real way of caching;The above 2, 3, and 4 cache technologies generally use time change judgment;You need to set a valid time for the cache file,Within this valid time, the same access will first fetch the contents of the cache file,But exceeds the set cache time,You need to get the data back from the database,And produce the latest cache file;For example, I set the homepage of our mall to be updated every 2 hours;

5.Cache by content change

This is not an independent cache technology,To be used in combination;Is when the database content is modified,Update the cache file immediately;

For example, a mall with a lot of people,There are many products,The commodity list must be relatively large,The pressure on this watch is also relatively heavy;We can cache the product display page;

When the merchant modifies the information of this product in the background,Click Save.We update the cache file at the same time;So, when buyers access this product information,Actually accessing a static page,No need to access the database again;

Imagine if the product page is not cached,Then every time you visit a product, you have to check it in the database.If 100,000 people browse the product online,Then the server is under pressure;

6.Memory cache

Mention this,Maybe everyone thinks of memcached first;memcached is a high-performance distributed memory cache server. The general purpose of use is,Query results through a cache database,Reduce database accesses,To increase the speed and scalability of dynamic web applications.

It is the information that will need to be cached,Cached in system memory,When information is needed,Fetch directly into memory;The more commonly used method is the key->value method;

<?php
   $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
?>

7, apache cache module

After Apache is installed,It is not allowed to be cached. If an external cache or squid server is required for web acceleration,You need to set it in htttpd.conf,Of course, the prerequisite is to activate the mod_cache module when installing apache.

When installing apache:./configure --enable-cache --enable-disk-cache --enable-mem-cache

8.php apc cache extension

php has an apc cache extension,Below php_apc.dll, you need to load this module first,Then configure it in php.ini:

  extension=php_apc.dll
   apc.rfc1867=on
   upload_max_filesize=100m
   post_max_size=100m
   apc.max_file_size=200m
   upload_max_filesize=1000m
   post_max_size=1000m
   max_execution_time=600;the maximum time (in seconds) for each php page to run, default 30 seconds
   max_input_time=600;maximum time required for each php page to receive data,Default 60
   memory_limit=128m;the maximum memory consumed by each php page,8m by default

Opcode cache

we know,The execution process of php can be shown with the following figure:

First the php code is parsed into tokens, then it is compiled into opcode code, and finally the opcode code is executed and the result is returned;So, 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,It will directly find the opcode code in the cache and directly perform the last step.No intermediate steps are needed.

php
  • Previous ASPNET colorful drop-down box development examples
  • Next jQuery implementation of editable table examples (2)