【问题标题】:How to clear OutputCache in Mono MVC2 application如何在 Mono MVC2 应用程序中清除 OutputCache
【发布时间】:2025-12-16 16:35:01
【问题描述】:

AddCacheItemDependency 用于使用下面的代码清除 Mono Apache MVC2 应用程序中的 OutputCache。 这在Clearing Page Cache in ASP.NET中有描述

在 Mono 中,OutputCache 不会被清除。 查看 GitHub 中的源代码表明 AddCacheItemDependency 未在 Mono 中实现。 如何解决这个问题,以便可以清除 OutputCache ?

安德鲁斯。

[OutputCache(Duration = 3600, VaryByParam = "none")]
public ActionResult Index()
{
  HttpContext.Current.Response.AddCacheItemDependency("Pages");
  return View();
}

public ActionResult Refresh()
{
HttpRuntime.Cache.Insert( "Pages", DateTime.Now);
}

在 Global.asax.cs 中:

protected void Application_Start()
{
HttpRuntime.Cache.Insert( "Pages", DateTime.Now);
}

【问题讨论】:

    标签: c# asp.net-mvc asp.net-mvc-3 mono outputcache


    【解决方案1】:

    您是否尝试过手动删除输出缓存?

    喜欢:

    var urls = new List<string> {
                        Url.Action("Index", "ControllerName", new { area = "AreaName" }))
                };
    urls.ForEach(HttpResponse.RemoveOutputCacheItem);
    

    【讨论】:

    • 这需要知道确切的网址。 Url 还可以包含查询字符串参数,这些参数可能会有所不同。如何获取缓存中的所有网址?