首页 > 学院 > 开发设计 > 正文

服务器缓存不依赖URL的方法(OutPutCache)及客户端不缓存,完美做法

2019-11-17 03:36:48
字体:
来源:转载
供稿:网友

可以避免客户端缓存:

<%Response.Cache.SetNoStore();%>

----------------------------------------------------------------------------------------------------------------------

经过测试,下面的方式会清空服务器端的缓存。不适合配合Global.asax使用

<% Response.CacheControl = "no-cache" %>
<% Response.AddHeader "PRagma", "no-cache" %>
<% Response.Expires = -1 %>s

----------------------------------------------------------------------------------------------------------------------

服务器缓存方式:

Global.asax:

新增函数:

   public override string GetVaryByCustomString(HttpContext context, string custom)
        {
            if ("Student".Equals(custom))
            {
                return string.Format("{0}", "动态数据");
            }
            return base.GetVaryByCustomString(context, custom);
        }

页面:

  <%@ OutputCache Duration="180" VaryByCustom="Student" VaryByParam="none"  %>


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表