2015-01-21 46 views
0

我使用这个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 = "" }); 

我试过多个版本,但没有运气。有谁能够帮助我?

+0

感谢Marino:解决方法是使用'cacheManager.RemoveItem(“News”,“LastArticles”,new {numberOfArticles = 2});' – 2015-01-21 12:55:56

回答

1

我相信你不应该明确定义(空)区域。虽然该区域是路由的重要组成部分,但MVCDonutCaching在定义内部密钥方面做了一些奇怪的事情。也许MVCDonutCache有关于区域的错误。

+1

您的权利!解决方案是删除空白区域。奇怪的是,如果您使用标准的'OutputCache',则必须使用空白区域。看起来像Nuget包中的一个错误。 – 2015-01-21 12:54:05