我使用这个MVCDonutCaching Nuget package,因为在tutorial他们说这是可能的儿童行动。MVCDonutCaching - 如何删除儿童动作缓存MVC甜甜圈缓存
This question对我不起作用,或者我没有正确理解它。
如果有人知道如何删除具有标准OutputCache
属性的子缓存,那么也可以!
我已经搜索了这个,但我找不到它。在这里看到一个例子:HomeController的(主页)的
Index操作:
[AllowAnonymous]
public ActionResult Index()
{
return View();
}
ChildAction的NewsController的:HomeController的的
[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());
}
索引视图:
@{ Html.RenderAction("LastArticles", "News", new { numberOfArticles = 2 }); }
清除缓存我有一个Admin ar在我的应用程序中,通过一个控制器和一个动作来更新子动作存储的数据。所以当新闻文章更新时。应该在主页上刷新缓存。
在这一行动,我有以下代码:
var cacheManager = new OutputCacheManager();
cacheManager.RemoveItem("News", "LastArticles", new { area = "", numberOfArticles = 2 });
cacheManager.RemoveItem("News", "LastArticles", new { area = "" });
我试过多个版本,但没有运气。有谁能够帮助我?
感谢Marino:解决方法是使用'cacheManager.RemoveItem(“News”,“LastArticles”,new {numberOfArticles = 2});' – 2015-01-21 12:55:56