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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With