`
wudixiaotie
  • 浏览: 136834 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

(转载)"Cache-control”常见的取值private、no-cache、max-age、must-revalidate及其用意

 
阅读更多

转自:http://www.cnblogs.com/kaima/archive/2009/10/13/1582337.html

 

网页的缓存是由HTTP消息头中的“Cache-control”来控制的,常见的取值有private、no-cache、max-age、must-revalidate等,默认为private。其作用根据不同的重新浏览方式分为以下几种情况:
(1) 打开新窗口
如果指定cache-control的值为private、no-cache、must-revalidate,那么打开新窗口访问时都会重新访问服务器。而如果指定了max-age值,那么在此值内的时间里就不会重新访问服务器,例如:
Cache-control: max-age=5
表示当访问此网页后的5秒内再次访问不会去服务器
(2) 在地址栏回车
如果值为private或must-revalidate(和网上说的不一样),则只有第一次访问时会访问服务器,以后就不再访问。如果值为no-cache,那么每次都会访问。如果值为max-age,则在过期之前不会重复访问。
(3) 按后退按扭
如果值为private、must-revalidate、max-age,则不会重访问,而如果为no-cache,则每次都重复访问
(4) 按刷新按扭
无论为何值,都会重复访问

当指定Cache-control值为“no-cache”时,访问此页面不会在Internet临时文章夹留下页面备份。
另外,通过指定“Expires”值也会影响到缓存。例如,指定Expires值为一个早已过去的时间,那么访问此网时若重复在地址栏按回车,那么每次都会重复访问:
Expires: Fri, 31 Dec 1999 16:00:00 GMT

在ASP中,可以通过Response对象的Expires、ExpiresAbsolute属性控制Expires值;通过Response对象的CacheControl属性控制Cache-control的值,例如:
Response.ExpiresAbsolute = #2000-1-1# ' 指定绝对的过期时间,这个时间用的是服务器当地时间,会被自动转换为GMT时间
Response.Expires = 20  ' 指定相对的过期时间,以分钟为单位,表示从当前时间起过多少分钟过期。
Response.CacheControl = "no-cache" 

分享到:
评论

相关推荐

    Cache-control使用Cache-control:private学习笔记

    - **后退按钮**: private、must-revalidate和max-age通常不重新请求,no-cache则每次都请求。 - **刷新按钮**: 不论Cache-Control值为何,都会重新向服务器请求资源。 4. **Expires头与Pragma:no-cache** - `...

    http头部cache-control字段解析

    例如,`Cache-Control: max-age=3600`表示响应在接下来的3600秒内可以被缓存并重用,无需向源服务器再次验证。 2. `s-maxage` 与`max-age`类似,但`s-maxage`是针对共享缓存(如代理服务器)的,它覆盖了响应中`max...

    http cache-control详解

    - **按后退按钮**:`private`、`must-revalidate`和`max-age`通常不会重复请求,除非设置为`no-cache`,则每次都重新请求。 - **刷新按钮**:无论`Cache-Control`设置为何值,都会向服务器重新请求资源,确保获取...

    Go-Go的缓存控制中间件添加ETag头(内容的md5)和Cache-Control头

    `Cache-Control`头则提供了更精细的缓存控制策略,包括设置缓存的max-age、public/private、no-cache、must-revalidate等指令。例如,`Cache-Control: max-age=3600`表示资源可以在客户端缓存一小时,而`Cache-...

    SERVLET 上传文件原理,Cache-Contro,java编码,jbpm原理

    常见的值有`no-cache`、`max-age`、`must-revalidate`等。例如,`Cache-Control: no-cache`意味着每次请求都应该向服务器验证是否更新了资源;`Cache-Control: max-age=3600`表示响应可以被缓存一小时。理解并正确...

    request的使用.txt

    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。各个消息中的指令含义...

    为何要小心Nginx的add_header指令详解

    前言 大家都知道,nginx配置文件通过使用add_header指令来设置response header。 昨天无聊用curl查看一个站点的...cache-control: max-age=3, must-revalidate last-modified: Thu, 07 Feb 2019 03:54:54 GMT X-Cach

    apache提示没有设置 max-age or expires解决办法.docx

    Header set Cache-Control "max-age=3600, must-revalidate" ``` 这里,我们使用了`FilesMatch`指令来匹配文件扩展名,并设置了不同的`max-age`值。`public`指示资源可被任何缓存(公共缓存)存储,`must-...

    HTTP+JS+浏览器缓存技术

    Cache-Control 的值可以是 public、private、no-cache、no-store、no-transform、must-revalidate、proxy-revalidate、max-age 等。 三、清除浏览器缓存的方法 有时候我们需要清除浏览器缓存,因为缓存可能误事,...

    vue项目强制清除页面缓存的例子

    add_header Cache-Control "no-cache,must-revalidate,proxy-revalidate,max-age=0"; root /var/www/example-fe/dist/; index index.html index.htm; try_files $uri/index.html; } ``` 此配置确保了每次HTML...

    sinatra-cache-control

    常见的`Cache-Control`指令包括`public`、`private`、`no-cache`、`max-age`等。例如,`public`指示响应可被任何中间缓存存储,`max-age`则指定了缓存的有效期。 在Sinatra中,我们可以通过设置响应头来添加`Cache-...

    用PHP程序实现支持页面后退的两种方法

    第一,使用Header方法设置消息头Cache-control QUOTE: header(‘Cache-control: private, must-revalidate’); //支持页面回跳 第二,使用session_cache_limiter方法 QUOTE: //注意要写在session_start方法之前 ...

    Jetty缓存锁定问题解决(javascript,css锁定问题)

    <max-age>0</max-age> <must-revalidate>true</must-revalidate> </cache-control> </cache-controls> ``` 这将使每次请求都强制从服务器获取资源,而不是使用缓存。 2. `<session-config>`元素:用于设置...

    页面的缓存与不缓存设置及html页面中meta的作用

    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"> ``` 然而,`meta`标签的缓存控制作用通常不如HTTP头信息强大,因为它们只能影响到浏览器的缓存行为,而不能影响到中间缓存...

    让PHP支持页面回退的两种方法[转]

    第一,使用Header方法设置消息头Cache-control header(‘Cache-control: private, must-revalidate’); //支持页面回跳  第二,使用session_cache_limiter方法 //注意要写在session_start方法之前 session_...

    让PHP支持页面回退的两种方法

    第一,使用Header方法设置消息头Cache-control header(‘Cache-control: private, must-revalidate’); //支持页面回跳  第二,使用session_cache_limiter方法 //注意要写在session_start方法之前 session_...

    HTTP1.1消息头

    1. Cache-Control:用于控制缓存机制,包括public、private、no-cache、no-store、no-transform、must-revalidate、proxy-revalidate、max-age 和 s-maxage 等取值。 2. Connection:用于指定是否继续保持与服务器的...

Global site tag (gtag.js) - Google Analytics