支持动态加速的CDN一般都是遵循cache-control设置来做缓存的,比如百度云加速,所以cache-control设置显得非常重要。今天我们就来说下cache-control怎么设置:
cache-control设置是在WEB服务器上设置的。
Apache .htaccess文件添加代码
<filesMatch "\.(ico|gif|jpg|png|jpeg)$">
ExpiresActive On
ExpiresDefault "access plus 11 month"
Header append Cache-Control "public"
</filesMatch>
Nginx
location ~ .*\.php$ {
if ($request_uri !~ ^/dynamicimg/) {
add_header Cache-Control "no-cache";
add_header Pragma no-cache;
}
}
IIS config.xml文件
<configuration>
<system.webServer>
<staticContent>
<clientCache cache-controlMode="UseExpires" httpExpires="Tue, 19 Jan 2038 03:14:07 GMT" />
</staticContent>
</system.webServer>
</configuration>
PHP php.ini文件
session.cache_limiter = nocache 改为 session.cache_limiter = none 修改完后记得重启下服务器配置。 Cache-Control参数详解: no-cache: 数据内容不能被缓存, 每次请求都重新访问服务器, 若有max-age, 则缓存期间不访问服务器. no-store: 不仅不能缓存, 连暂存也不可以(即: 临时文件夹中不能暂存该资源) private: 只能在浏览器中缓存, 只有在第一次请求的时候才访问服务器, 若有max-age, 则缓存期间不访问服务器. public: 可以被任何缓存区缓存, 如: 浏览器、服务器、代理服务器等 max-age: 相对过期时间, 即以秒为单位的缓存时间. no-cache, private: 打开新窗口时候重新访问服务器, 若设置max-age, 则缓存期间不访问服务器. private, 正数的max-age: 后退时候不会访问服务器 no-cache, 正数的max-age: 后退时会访问服务器
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。