I'm using this MVCDonutCaching Nuget package because in the tutorial they said this was possible with child actions.
This question didn't work for me or I didn't understand it correctly.
If someone knows how to delete the child cache with the standard OutputCache
attribute, then that is alright as well!
I've searched for this but I can't find it. See here an example:
Index action of the HomeController (homepage):
[AllowAnonymous]
public ActionResult Index()
{
return View();
}
ChildAction of the NewsController:
[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());
}
Index view of the HomeController:
@{ Html.RenderAction("LastArticles", "News", new { numberOfArticles = 2 }); }
To clear the cache I have an Admin area in my application with a controller and action in it to update the data stored by the child action. So when a news article is updated. The cache should get refreshed on the homepage.
In that action I have the following code:
var cacheManager = new OutputCacheManager();
cacheManager.RemoveItem("News", "LastArticles", new { area = "", numberOfArticles = 2 });
cacheManager.RemoveItem("News", "LastArticles", new { area = "" });
I tried multiple versions but without luck. Can anybody help me?
I believe you shouldn't explicitly define the (empty) area. Although the area's an important part of the routing, MVCDonutCaching does something weird in defining an internal key. Perhaps MVCDonutCache has a bug concerning area's.