I am using OutputCache on an Action like this:
[OutputCache(Duration = 14400, VaryByParam = "none")]
public ContentResult Catalog()
{
return ...;
}
and my RegisterRoutes function in Global.asax.cs contains the route:
routes.MapRoute(
"XMLRoute", // Route name
"{site}/catalog.xml", // URL with parameters
new { controller = "Home", action = "Catalog" } // Parameter defaults
);
The route maps urls like:
- example.com/site1/catalog.xml
- example.com/site2/catalog.xml
- example.com/whatever/catalog.xml
to the Catalog Action.
I believe that the expected result would be to return static content after the first request for every parameter passed, but the content is not cached properly. Should I modify the Catalog action to use a param and then specify VarybyParam = "none" and add a param with UrlParameter.Optional at the MapRoute function or is there something else going on here?
After much trial and error I found that the best way was to use:
And provide the parameters using redirect so that the defaults are used and cached content is shown.