0

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?

Community
  • 1
  • 1
LockTar
  • 5,364
  • 3
  • 46
  • 72
  • Thanks to Marino: the solution is to use `cacheManager.RemoveItem("News", "LastArticles", new { numberOfArticles = 2 });` – LockTar Jan 21 '15 at 12:55

1 Answers1

1

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.

  • 1
    Your right! Deleting the empty area was the solution. Strange enough you must use the empty area if you use the standard `OutputCache`. Looks like a bug in the Nuget package. – LockTar Jan 21 '15 at 12:54