Set static content cache time
The code is as follows: |
Copy code |
$ Interval = 60*60*6; // 6 hours Header ("Last-Modified:". gmdate ('R', $ max )); Header ("Expires:". gmdate ("r", ($ max + $ interval ))); Header ("Cache-Control: max-age = $ interval "); |
We will add the above code to the beginning of the PHP file. The following describes the four lines of code.
For example, my code
The code is as follows: |
Copy code |
$ Interval = 60*60*6; // 6 hours Header ("Last-Modified:". gmdate ('R', $ max )); Header ("Expires:". gmdate ("r", ($ max + $ interval ))); Header ("Cache-Control: max-age = $ interval "); $ Aid = intval (isset ($ _ POST ['aid '])? $ _ POST ['aid ']: 0 ); If (! $ Aid) { Echo 'undefined ads '; } Else if ($ aid = 1) { Echo 'load ad content '; }
|
The first line: $ interval tells you that it has been set for six hours. You can customize it here.
Row 2: send a Last-Modified request to the client browser, which calls the corresponding date based on the gmdate parameter r.
Row 3: Set the expiration time of Expires.
Row 4: Set the max-age = $ interval date of Cache-Control.
The test result is excellent.