zoukankan      html  css  js  c++  java
  • 禁用IE缓存

    HTTP消息报头包括普通报头、请求报头、响应报头、实体报头。

    普通报头中的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时都可以清空缓存

  • 相关阅读:
    智器SmartQ T7实体店试用体验
    BI笔记之SSAS库Process的几种方案
    PowerTip of the Day from powershell.com上周汇总(八)
    PowerTip of the Day2010071420100716 summary
    PowerTip of the Day from powershell.com上周汇总(十)
    PowerTip of the Day from powershell.com上周汇总(六)
    重新整理Cellset转Datatable
    自动加密web.config配置节批处理
    与DotNet数据对象结合的自定义数据对象设计 (二) 数据集合与DataTable
    在VS2003中以ClassLibrary工程的方式管理Web工程.
  • 原文地址:https://www.cnblogs.com/mingforyou/p/3281964.html
Copyright © 2011-2022 走看看