I have done some caching tests. Here is what I found:
You must clear the cache for each route that will lead to your action. If you have 3 routes that lead to the same action in your controller, you will have one cache for each route.
Let's say I have this config route:
routes.MapRoute( name: "config1", url: "c/{id}", defaults: new { controller = "myController", action = "myAction", id = UrlParameter.Optional } ); routes.MapRoute( name: "Defaultuser", url: "u/{user}/{controller}/{action}/{id}", defaults: new { controller = "Accueil", action = "Index", user = 0, id = UrlParameter.Optional } ); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Accueil", action = "Index", id = UrlParameter.Optional } );
Then these 3 routes lead to myAction in myController with the myParam parameter:
If my action is as follows
public class SiteController : ControllerCommon { [OutputCache(Duration = 86400, VaryByParam = "id")] public ActionResult Cabinet(string id) { return View(); } }
I will have one cache for each route (in this case 3). Therefore, I will have to cancel each route.
Like this
private void InvalidateCache(string id) { var urlToRemove = Url.Action("myAction", "myController", new { id});
Daniel May 7 '15 at 14:47 2015-05-07 14:47
source share