zl程序教程

您现在的位置是:首页 >  后端

当前栏目

禁用IE缓存详解编程语言

缓存编程语言 详解 IE 禁用
2023-06-13 09:20:39 时间

 

普通报头中的Cache-Control用于指定缓存指令,缓存指令是单向的(响应中出现的缓存指令在请求中未必会出现),且是独立的(一个消息的缓存指令不会影响另一个消息处理的缓存机制),HTTP1.0使用的类似的报头域为Pragma。

请求时的缓存指令包括: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、s-maxage。

例:为了指示IE浏览器(客户端)不要缓存页面,服务器端的jsp程序可以编写如下:

response.setHeader(“Cache-Control”, “no-cache”);

//response.setHeader(“Pragma”, “no-cache”);作用相当于上行代码,通常两者合用

Expires实体报头域给出响应过期的日期和时间。为了让代理服务器或浏览器在一段时间以后更新缓存中(再次访问曾访问过的页面时,直接从缓存中加载,缩短响应时间和降低服务器负载)的页面,我们可以使用Expires实体报头域指定页面过期时间。

例:Expires:Thu,15 Sep 2006 16:23:12 GMT

HTTP1.1的客户端和缓存必须将其他非法的日期格式(包括0)看作已经过期。如:为了让浏览器不要缓存页面,也可以利用Expires实体报关域,设置为0,jsp程序如下:

response.setDateHeader(“Expires”, “0”);

  //JSP

禁止缓存代码

 response.setHeader( Pragma , No-cache );

 response.setHeader( Cache-Control , no-cache );

 response.setDateHeader( Expires , 0);

 response.flushBuffer();

 另,网上各种禁客户端缓存总结如下:

 

 

HTM网页

  META  HTTP-EQUIV= pragma   CONTENT= no-cache  

  META  HTTP-EQUIV= Cache-Control   CONTENT= no-cache,  must-revalidate  

  META  HTTP-EQUIV= expires   CONTENT= Wed,  26  Feb  1997  08:21:57  GMT

 

  ASP网页

  % 

  Response.Expires  =  -1 

  Response.ExpiresAbsolute  =  Now()    1  Response.cachecontrol  =  no-cache  

  %  

  PHP网页

  header( Expires:  Mon,  26  Jul  1997  05:00:00  GMT ); 

  header( Cache-Control:  no-cache,  must-revalidate ); 

  header( Pragma:  no-cache ); 

  JSP 

  response.setHeader( Pragma , No-Cache ); 

  response.setHeader( Cache-Control , No-Cache ); 

  response.setDateHeader( Expires ,  0); 

  C#中禁止cache的方法! 

  Response.Buffer=true; 

  Response.ExpiresAbsolute=System.DateTime.Now.AddSeconds(-1); 

  Response.Expires=0; 

  Response.CacheControl= no-cache  

在 %@  Page  language= c#   Codebehind= A.aspx.cs   AutoEventWireup= false   Inherits= *.*   % 下面加上以下的代码: 

  %@  OutPutCache  Location= None %   能每次页面Load时都可以清空缓存

 

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/13379.html

cphp