【问题标题】:MVCDonutCaching - how to remove Child action cache MVC Donut CachingMVCDonutCaching - 如何删除子动作缓存 MVC Donut Caching
【发布时间】:2015-03-19 15:13:06
【问题描述】:

我正在使用这个 MVCDonutCaching Nuget package,因为在 tutorial 他们说这可以通过子操作来实现。

This question 对我不起作用或我没有正确理解。

如果有人知道如何使用标准OutputCache 属性删除子缓存,那也没关系!

我已经搜索过这个,但我找不到它。看这里的一个例子:

HomeController(主页)的索引操作:

[AllowAnonymous]
public ActionResult Index()
{
   return View();
}

NewsController 的 ChildAction:

[AllowAnonymous]
[ChildActionOnly]
[DonutOutputCache(Duration = 600, Location = OutputCacheLocation.Server)]
public PartialViewResult LastArticles(int numberOfArticles)
{
    return PartialView("_LastArticles", db.NewsArticles
    .Include(i => i.Tags)
    .Include(i => i.SeoTags)
    .Where(n => n.Status == PublishStatus.Published)
    .OrderByDescending(n => n.PublishDate)
    .Take(numberOfArticles)
    .ToList());
}

HomeController 的索引视图:

@{ Html.RenderAction("LastArticles", "News", new { numberOfArticles = 2 }); }

为了清除缓存,我的应用程序中有一个 Admin 区域,其中包含一个控制器和一个动作,用于更新子动作存储的数据。因此,当更新新闻文章时。缓存应该在主页上刷新。

在该操作中,我有以下代码:

var cacheManager = new OutputCacheManager();
cacheManager.RemoveItem("News", "LastArticles", new { area = "", numberOfArticles = 2 });
cacheManager.RemoveItem("News", "LastArticles", new { area = "" });

我尝试了多个版本,但没有运气。有人可以帮帮我吗?

【问题讨论】:

  • 感谢马里诺:解决方案是使用cacheManager.RemoveItem("News", "LastArticles", new { numberOfArticles = 2 });

标签: c# asp.net-mvc outputcache donut-caching


【解决方案1】:

我认为您不应该明确定义(空)区域。尽管该区域是路由的重要组成部分,但 MVCDonutCaching 在定义内部键时做了一些奇怪的事情。也许 MVCDonutCache 有一个关于区域的错误。

【讨论】:

  • 你的权利!删除空白区域是解决方案。奇怪的是,如果你使用标准的OutputCache,你必须使用空白区域。看起来像 Nuget 包中的一个错误。
猜你喜欢
  • 2018-10-26
  • 2015-08-10
  • 2015-03-18
  • 2012-02-10
  • 2022-11-25
  • 2016-07-10
  • 2020-10-29
  • 1970-01-01
  • 2020-01-20
相关资源
最近更新 更多