代码之家  ›  专栏  ›  技术社区  ›  John Boker

Asp.Net输出缓存和过期

  •  4
  • John Boker  · 技术社区  · 15 年前

    如果没有,还有哪些缓存页面的方法允许我以这种方式进行编辑。

    -----------编辑-----------

    经过进一步的研究,我发现了一种似乎很有效的方法。

    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)
    

    3 回复  |  直到 12 年前
        1
  •  1
  •   Andre Gallo    15 年前

    你可以试试这个:

    private void RemoveButton_Click(object sender, System.EventArgs e)
    {
        HttpResponse.RemoveOutputCacheItem("/caching/CacheForever.aspx");
    }
    

    发件人: http://aspalliance.com/668

    谢谢

        2
  •  1
  •   some_guy    13 年前

    你的解决方案对我不起作用。然而经过一些测试后,我让它工作得很好。此代码将位于需要缓存的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;
    

    Response.AddCacheItemDependency 当我从更新数据时没有任何效果 Cache[key_refresh] .

        3
  •  0
  •   John Boker    14 年前

    经过进一步的研究,我发现了一种似乎很有效的方法。

    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)
    

    现在,只要知道依赖项缓存键,页面就可以过期。