清除用户控件的缓存

在global.assx中重写如下方法:
 public override string GetVaryByCustomString(HttpContext context, string arg)
        {
            if (arg == "news_ascx")
            {
                string value= HttpRuntime.Cache["news_ascx"];
                if (value == null)
                {

                    value = DateTime.Now.ToString();           
                 HttpRuntime.Cache.Insert("", value, null, DateTime.MaxValue, new TimeSpan(100,0,0,0),CacheItemPriority.Normal, null);

                }
                return value;
            }
            return base.GetVaryByCustomString(context, arg);
        }
在用户控件中News.ascx中添加如下属性

<%@ OutputCache Duration="86400" VaryByCustom="news_ascx" VaryByParam="none"  %>

在需要移除用户控件缓存的地方添加如下代码:
 Cache.Remove("news_ascx");

原文地址:https://www.cnblogs.com/mxw09/p/1872972.html