尽管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 }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2022-01-21
  • 2021-12-09
猜你喜欢
  • 2021-12-15
  • 2022-01-26
  • 2021-04-29
  • 2022-12-23
  • 2021-06-27
相关资源
相似解决方案