Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Response.RemoveOutputCacheItem with RedisOutputCacheProvider

I am using the Microsoft RedisOutputCacheProvider and have a very simple PartialView which I am caching based on the current user's SessionId via VaryByCustom:

[OutputCache(VaryByCustom = "User", Duration = 3600)]
[ChildActionOnly]
public ActionResult Notifications()
{
    return PartialView("Partials/Notifications");
}

This works great and caches as expected, however I wanted to manually expire this OutputCache from another page. I tried:

Response.RemoveOutputCacheItem("/Controller/Notifications");

But that doesn't seem to work. I also can't see any of the OutputCache keys via either my Redis store, or via my backend code, but I can definitely see the view being cached.

like image 604
CodingIntrigue Avatar asked Sep 18 '14 14:09

CodingIntrigue


1 Answers

Have you try something like this?

//  Get the url for the action method:
var staleItem = Url.Action("Action", "Controller");

//  Remove the item from cache
Response.RemoveOutputCacheItem(staleItem);

I think that you need to hold a reference to your ActionResult.

Best of luck :)

PS: Maybe this link will help you : The Blog of Dan Esparza

like image 165
Philippe Matray Avatar answered Nov 16 '22 16:11

Philippe Matray