
[英]Donut caching _Layout with mvcdonutcaching ASP.NET MVC
[英]MVCDonutCaching - how to remove Child action cache MVC Donut Caching
我使用的是MVCDonutCaching Nuget软件包,因为在本教程中他们说这可以通过子操作实现。
这个问题对我不起作用,或者我无法正确理解。
如果有人知道如何使用标准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 = "" });
我尝试了多个版本,但没有运气。 有谁能够帮助我?
我相信您不应该明确定义(空)区域。 尽管该区域是路由的重要组成部分,但是MVCDonutCaching在定义内部密钥方面做得很奇怪。 也许MVCDonutCache有一个关于区域的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.