int minutes = 10;
Date d = new Date();
String modDate = d.toGMTString();
String expDate = null;
expDate = (new Date(d.getTime() + minutes * 60000)).toGMTString(); //System.out.println(modDate); 31 Aug 2009 03:35:37 GMT
//System.out.println(expDate); 31 Aug 2009 03:55:37 GMTresponse.setHeader("Last-Modified", modDate);
response.setHeader("Expires", expDate);
response.setHeader("Cache-Control", "public"); // HTTP/1.1
Date d = new Date();
String modDate = d.toGMTString();
String expDate = null;
expDate = (new Date(d.getTime() + minutes * 60000)).toGMTString(); //System.out.println(modDate); 31 Aug 2009 03:35:37 GMT
//System.out.println(expDate); 31 Aug 2009 03:55:37 GMTresponse.setHeader("Last-Modified", modDate);
response.setHeader("Expires", expDate);
response.setHeader("Cache-Control", "public"); // HTTP/1.1
Expires是缓存失效时间,要求客户端在这个时间之后必须缓存失效,重新获取内容
这2个都是HTTP协议中的标准头字段,具体可以参考RFC2616中的定义13.3.1 Last-Modified Dates The Last-Modified entity-header field value is often used as a cache
validator. In simple terms, a cache entry is considered to be valid
if the entity has not been modified since the Last-Modified value.14.21 Expires The Expires entity-header field gives the date/time after which the
response is considered stale. A stale cache entry may not normally be
returned by a cache (either a proxy cache or a user agent cache)
unless it is first validated with the origin server (or with an
intermediate cache that has a fresh copy of the entity). See section
13.2 for further discussion of the expiration model.