C# Asp.Net输出缓存和过期
我在包含usercontrol的页面上使用Asp.net OutputCache,在某些情况下,编辑usercontrol时,我希望能够使页面缓存过期并用新数据重新加载页面 是否有任何方法可以在usercontrol中执行此操作 如果没有,还有哪些缓存页面的方法允许我以这种方式进行编辑 -----------编辑-----------C# Asp.Net输出缓存和过期,c#,asp.net,vb.net,caching,outputcache,C#,Asp.net,Vb.net,Caching,Outputcache,我在包含usercontrol的页面上使用Asp.net OutputCache,在某些情况下,编辑usercontrol时,我希望能够使页面缓存过期并用新数据重新加载页面 是否有任何方法可以在usercontrol中执行此操作 如果没有,还有哪些缓存页面的方法允许我以这种方式进行编辑 -----------编辑----------- 经过进一步的研究,我发现了一种似乎很有效的方法 Dim cachekey As String = String.Format("Calendar-{0}", ca
经过进一步的研究,我发现了一种似乎很有效的方法
Dim cachekey As String = String.Format("Calendar-{0}", calendarID)
HttpContext.Current.Cache.Insert(cachekey, DateTime.Now, Nothing, System.DateTime.MaxValue, System.TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, Nothing)
Response.AddCacheItemDependency(cachekey)
Dim cachekey As String = String.Format("Calendar-{0}", calendarID)
HttpContext.Current.Cache.Insert(cachekey, DateTime.Now, Nothing, System.DateTime.MaxValue, System.TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, Nothing)
Response.AddCacheItemDependency(cachekey)
这将向页面缓存对象添加依赖项,然后要使其过期,请执行以下操作:
Dim cachekey as string = String.Format("Calendar-{0}", CalendarID)
HttpContext.Current.Cache.Insert(cachekey, DateTime.Now, Nothing, System.DateTime.MaxValue, System.TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, Nothing)
Dim cachekey as string = String.Format("Calendar-{0}", CalendarID)
HttpContext.Current.Cache.Insert(cachekey, DateTime.Now, Nothing, System.DateTime.MaxValue, System.TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, Nothing)
现在,只要知道依赖项缓存键,页面就可能过期。您可以尝试以下方法:
private void RemoveButton_Click(object sender, System.EventArgs e)
{
HttpResponse.RemoveOutputCacheItem("/caching/CacheForever.aspx");
}
发件人:
谢谢。经过进一步研究,我发现了一种似乎很有效的方法
Dim cachekey As String = String.Format("Calendar-{0}", calendarID)
HttpContext.Current.Cache.Insert(cachekey, DateTime.Now, Nothing, System.DateTime.MaxValue, System.TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, Nothing)
Response.AddCacheItemDependency(cachekey)
Dim cachekey As String = String.Format("Calendar-{0}", calendarID)
HttpContext.Current.Cache.Insert(cachekey, DateTime.Now, Nothing, System.DateTime.MaxValue, System.TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, Nothing)
Response.AddCacheItemDependency(cachekey)
这将向页面缓存对象添加依赖项,然后要使其过期,请执行以下操作:
Dim cachekey as string = String.Format("Calendar-{0}", CalendarID)
HttpContext.Current.Cache.Insert(cachekey, DateTime.Now, Nothing, System.DateTime.MaxValue, System.TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, Nothing)
Dim cachekey as string = String.Format("Calendar-{0}", CalendarID)
HttpContext.Current.Cache.Insert(cachekey, DateTime.Now, Nothing, System.DateTime.MaxValue, System.TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, Nothing)
现在,只要知道依赖项缓存键,页面就可能过期。您的解决方案对我不起作用。然而。。。经过一些测试后,我让它工作得很好。此代码将位于需要缓存的UserControl页面加载中
string key_refresh = "refresh_id_" + YourID;
Cache[key_refresh] = DateTime.Now.ToString();
CacheDependency dep = new CacheDependency(null, new string[] { key_refresh });
this.CachePolicy.Dependency = dep;
由于某些原因,当我从Cache[key\u refresh]
更新数据时,使用Response.AddCacheItemDependency
没有任何效果
在我的例子中,我按用户ID缓存我的控件,因此每个用户都有一个具有不同数据的不同版本的控件,我使用VaryByCustom单独缓存它。是的,这似乎是唯一的例子,但它没有考虑VaryByParams,因此,如果我使该页面过期,我认为缓存中仍然会有相同页面的数据,并且具有不同的查询字符串。