【发布时间】: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