|
|
Posted on 11/2/2014 1:45:30 PM
|
|
|
|

Apache's expiration policy can be set through Apache's mod_expires and mod_headers modules:
1) Module mod_expires Settings:
Allows control of HTTP "Expires" and "Cache-Control" headers via configuration files
The main function of the mod_expires module is to automatically generate Expires tags and Cache-Control tags in the page header information, thereby reducing the frequency and frequency of client visits, reducing unnecessary traffic and increasing access speed
mod_expires is one of the simplest modules in Apache, with only three instructions
ExpiresActive directive: Turn on or off the function that generates the "Expires:" and "Cache-Control:" headers.
ExpiresByType directive: Specifies the expiration time of MIME-type documents (e.g., text/html).
ExpiresDefault directive: defaults the expiration time for all documents.
How to write the expiration time
“access plus 1 month”
“access plus 4 weeks”
“now plus 30 days”
“modification plus 5 hours 3 minutes”
A2592000
M604800
access, now, and A have the same meaning, meaning that the expiration time starts from the time of access.
modification and M have the same meaning, meaning that the expiration time starts from the last modification time of the accessed file.
Therefore, the latter writing method only works for static files, while dynamic pages generated by scripts are not affected by it
Configuration example:
Expires mod_expires Active On
ExpiresDefault "access plus 6 months"
ExpiresByType image/* "access plus 10 years"
ExpiresByType text/* "access plus 10 years"
ExpiresByType application/* "access plus 30 minutes"
Verification: image/jpeg cache time is 315360000s (10 years)
If you set image/jpeg to not cache (max-age set to 0s):
# ExpiresByType image/* "access plus 10 years"
ExpiresByType image/* A0
2) Module mod_headers settings:
# YEAR (1 year cache time for flv, gif, ico file types)
Header set Cache-Control “max-age=2592000″
# WEEK (pdf.swf, js, css cache time is a week)
Header set Cache-Control “max-age=604800″
# NEVER CACHE (jsp.swf, ico file type is not cached)
Header set Expires “Thu, 01 Dec 2003 16:00:00 GMT”
Header set Cache-Control “no-store, no-cache, must-revalidate”
Header set Pragma “no-cache”
|
Previous:If the cache-control of the page header is set to no-cache, will the access be to the back server through the CDN?Next:Using the CDN service, IIS cache policy settings
|