Any valid HTTP headers can be put in these files. This provides another way to apply the Expires header, and it's a way to add the Cache-Control headers. The relevant Cache-Control headers are:
Cache-Control : max-age = [delta-seconds]
Modifies the expiration mechanism, overriding the Expires header. Max-age implies Cache-Control : public.
Cache-Control : public
Indicates that the object may be stored in a cache. This is the default.
Cache-Control : private
Cache-Control : private = [field-name]
Indicates that the object (or specified field) must not be stored in a shared cache and is intended for a single user. It may be stored in a private cache.
Cache-Control : no-cache
Cache-Control : no-cache = [field-name]
Indicates that the object (or specified field) may be cached, but may not be served to a client unless revalidated with the origin server.
Cache-Control : no-store
Indicates that the item must not be stored in nonvolatile storage, and should be removed as soon as possible from volatile storage.
Cache-Control : no-transform
Proxies may convert data from one storage system to another. This directive indicates that (most of) the response must not be transformed. (The RFC allows for transformation of some fields, even with this header present.)
Cache-Control : must-revalidate
Cache-Control : proxy-revalidate
Forces the proxy to revalidate the page even if the client will accept a stale response. Read the RFC before using these headers, there are restrictions on their use.
Caveats and gotchas
*
HTTP/1.0 has minimal cache control and only understands the Pragma: no-cache header. Caches using HTTP/1.0 will ignore the Expires and Cache-Control headers.
*
None of the Cache-Control directives ensure privacy or security of data. The directives "private" and "no-store" assist in privacy and security, but they are not intended to substitute for authentication and encryption.
*
This article is not a substitute for the RFC. If your are implementing the Cache-Control headers, do read the RFC for a detailed description of what each header means and what the limits are.
在jsp页面中
<%
String path = request.getContextPath();
HashMap> discounts = DiscountManager.getInnerDiscount();
response.setHeader("Cache-Control","public,max-age=600");
response.setDateHeader("Expires",(new Date()).getTime() + 1000 * 60 * 10);
%>
在HtML代码中
servlet
response.setHeader("Pragma","No-cache");
response.setDateHeader("Expires",0);
response.setHeader("Cache-Control","no-cache");
.Cache-Control头域
Cache-Control指定请求和响应遵循的缓存机制。在请求消息或响应消息中设置Cache-Control并不会修改另一个消息处理过程中的缓存处理过程。请求时的缓存指令包括no-cache、no-store、max-age、max-stale、min-fresh、only-if- cached,响应消息中的指令包括public、private、no-cache、no-store、no-transform、must- revalidate、proxy-revalidate、max-age。各个消息中的指令含义如下:
Public指示响应可被任何缓存区缓存。
Private指示对于单个用户的整个或部分响应消息,不能被共享缓存处理。这允许服务器仅仅描述当用户的部分响应消息,此响应消息对于其他用户的请求无效。
no-cache指示请求或响应消息不能缓存
no-store用于防止重要的信息被无意的发布。在请求消息中发送将使得请求和响应消息都不使用缓存。
max-age指示客户机可以接收生存期不大于指定时间(以秒为单位)的响应。
min-fresh指示客户机可以接收响应时间小于当前时间加上指定时间的响应。
max-stale指示客户机可以接收超出超时期间的响应消息。如果指定max-stale消息的值,那么客户机可以接收超出超时期指定值之内的响应消息。
分享到:
相关推荐
http头部cache-control字段解析,包含一个doc文件和一个pdf文件
网页缓存由 HTTP消息头中的Cache-control控制,常见取值有private、no-cache、max-age、must- revalidate等,默认为private
关于http cache-control详解,对学习http有很大的帮助
$ git clone git@github.com:jameslnewell/cache-control-spider.git $ npm i 用法 $ node index.js http://dev.online4.nib.com.au 原料药 方法 新的Crawler() 创建一个新的搜寻器。 .add(网址) 添加要爬网...
var cacheControl = require ( 'cache-control-midd' ) ;var app = express ( ) ;// Sets `Cache-Control` header to `public, max-age=600` and `Expires` too// 'minute' -> 10 minutes -> 600 secondsapp . get ...
npm install cache-header-control --save 用法 var express = require ( 'express' ) ; var setCacheHeader = require ( 'cache-header-control' ) ; var app = express ( ) ; app . use ( function ( req , res ...
安装composer require nomenjanahary/cache-control配置storage_cache_control : exclude_status : - " 5xx " - " 4xx " default_cache : maxAge : 3600 public : true # merge, replace override_strategy : merge ...
Go的缓存控制中间件添加ETag头(内容的md5)和Cache-Control头
与 JAX-RS Web 服务一起使用的注释,以向响应添加标头“Cache-Control”。 该项目应该被视为只是 JAX-RS 环境中注释功能的骨架。 用法 使用资源配置: 在package.name 中包含 CacheFilterFactory.java 并在您的 ...
nginx-缓存控制没有缓存清除模块的 Nginx 缓存控制插件部分代码是基于其他 Nginx Cache Plugins 的代码,但这是设计为简单、轻量级的实现== 具体.... == Mark Jaquith 提出了使用强制动态页面加载的标头的基本设计,...
这是一个用引导的项目。入门首先,运行开发服务器: npm run dev# oryarn dev 用浏览器打开以查看结果。 您可以通过修改pages/index.js来开始编辑页面。 页面在您编辑文件时自动更新。 可以在上访问。...
const withCacheControl = require ( 'connect-cache-control2' ) . withCacheControl ; app . get ( '/some-path' , withCacheControl ( { maxAge : '2 hours' , private : true } ) , function ( req , res ) {...
S3存储桶缓存控制 一个简单的nodeJS脚本,使用“ aws-sdk” NPM模块。 我之所以建立它,是因为在S3上我有一个装满图像的巨大存储桶,并且需要向所有这些图像添加缓存控制标头。 AWS S3(目前)不支持在存储桶级别...
Flask-CacheControl 描述: 一个轻量级的库,可以方便地在响应上设置Cache-Control标头。 使用cache_for,cache或dont_cache装饰器装饰视图函数。 利用Flask response.cache_control。 该扩展本身不提供任何缓存。...
它通过解析Cache-Control和其他标头,提供有关请求和响应的信息来做到这一点-但是cachecontrol并没有实现实际的缓存后端,只是实现了控制平面来决定是否可以响应特定的响应。用法cachecontrol.CachableResponse返回...
在IIS的Output caching中如果启用了User-mode caching将引起Cache-Control为no-cache,从而造成页面不能被浏览器或代理服务器缓存,下面看解决方法
koa-cache-router 用于koa的路由器缓存中间件。 对于缓存某些页面(例如/home很有用。安装npm i koa-cache-router --save用法var router = new(require('koa-router'))();var CacheMiddleware = require('koa-cache-...
人生苦短,只能用python啊。现在的python这么火,工资这么高,果断好好钻研一番。BAT面试题,满满的79页,希望帮到各位面试的...只不过Cache-Control的选择更多,设置更细致,如果同时设置的话,其优先级高于Expires
单纯的使用 xmlhttp.setRequestHeader("Cache-Control","no-cache")无效。 Cache-Control头域 Cache-Control指定请求和响应遵循的缓存机制。在请求消息或响应消息中设置Cache-Control并不会修改另一个消息处理...