- 当前机构其他课程
- 更多+
- 同类热点网络课程
- 暂无相关热门网络课程
| 1.基于页面缓存
对于页面:Default.aspx 如果页面顶部添加:
在后台管理中要移除很简单: System.Web.HttpResponse.RemoveOutputCacheItem(Page.ResolveUrl("Default.aspx"));
2.基于控件 对于控件WebUserControl.ascx 如果在顶部添加了
在后台管理中要实现的话有点麻烦,在博客园的博问请朋友们解答,查尔斯提供了一种解决方法。 实现如下: (1)添加VaryByCustom项,值为Cashgroupclass。
(2) 在Global.asax 中重写 GetVaryByCustomString 方法,代码如下:
代码 public override string GetVaryByCustomString(HttpContext context, string arg) { if (arg == "Cashgroupclass") { Cache objCache = HttpRuntime.Cache; Object _flag = objCache["Cashgroupclass"]; if (_flag == null) { _flag = DateTime.Now.Ticks.ToString(); objCache.Insert("Cashgroupclass", _flag); } return _flag.ToString(); } return base.GetVaryByCustomString(context, arg); } (3)在后台管理的移除页面添加如下代码: Cache objCache = HttpRuntime.Cache; if (objCache["Cashgroupclass"] != null) { objCache.Remove("Cashgroupclass"); }
代码 public static void SetCache(string CacheKey, object objObject, DateTime absoluteExpiration, TimeSpan slidingExpiration) { HttpRuntime.Cache.Insert(CacheKey, objObject, null, absoluteExpiration, slidingExpiration); } |
更多ASP.NET缓存的移除方法培训




