如何取消页面缓存

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

 

posted @ 2011-10-19 19:50  火星老蒋  阅读(612)  评论(0编辑  收藏  举报