i'm a MVC beginner and today i met a strange problem:I want to use OutputCache to enable cache on one action.code like this:
[OutputCache(Duration=86400,VaryByParam="none")]
public ActionResult Index(string id)
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
ViewBag.ID = id;
return View();
}
Notice that the "VaryByParam" property is "none",yes i want the server keep only one cache for the action, whatever the param was passed. and the routing code is this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
then i open the explore,the result is not what i want,for example i type:"http://localhost:27654/home/index/121212",the page come out and id"121212" was shown.but when i changed to "http://localhost:27654/home/index/12",and i see the page was changed ,id"12" was shown.
but if i refresh the page(para "id" not change),the datetime shown in the page didn't change,imply that asp.net has kept the cache VaryBy the "ID" para,not by my set. what's wrong?