zoukankan      html  css  js  c++  java
  • 如何取消页面缓存

    尽管BS架构下页面缓存可以为频繁访问的页面提高性能,但有时我们也需要取消这些缓存。

    前端取消缓存的几种方法:
     
    方法1:
    <head>
        <meta http-equiv="Expires" CONTENT="0">
        <meta http-equiv="Cache-Control" CONTENT="no-cache">
        <meta http-equiv="Pragma" CONTENT="no-cache">
    </head>
    方法2:
    在URL后面随机的加一些时间戳或随机数参数,比如:
    http://xxx/xxx/xxx.aspx?......&time=date().toString()

    后端取消缓存的几种方法:

    Page级别:
    1 Response.Buffer = true;
    2 Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
    3 Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
    4 Response.Expires = 0;
    5 Response.CacheControl = "no-cache";
    6 Response.Cache.SetNoStore();
    或是Global级别: 
    1 protected void Application_BeginRequest(Object sender, EventArgs e) 
    2 { 
    3         HttpContext.Current.Response.Cache.SetNoStore(); 
    4 }
    5 
    6 <%@ OutPutCache Location="None"%>
    页面基类:
     1 public class PageBase : Page 
     2 { 
     3     public PageBase()
     4     {
     5     } 
     6 
     7     protected override OnLoad(EventArgs e)
     8     { 
     9         Response.Cache.SetNoStore(); 
    10         base.OnLoad(); 
    11     } 
    12 }
  • 相关阅读:
    第六周 组合数据类型
    第五周 函数和代码复用
    第四周 程序的控制结构
    第三周 Python基本数据类型
    python库
    sublime text3自定义设置及快捷键大全
    Sublime Text3插件安装教程
    Linux 标准目录结构
    快学Scala-10--List 和Set
    快学Scala-09--模式匹配
  • 原文地址:https://www.cnblogs.com/jiangdaoli/p/3180196.html
Copyright © 2011-2022 走看看