Issue with ASP .Net MVC 2.0 Caching

205 views Asked by At

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?

1

There are 1 answers

0
gmakrygiannis On BEST ANSWER

After much trial and error I found that the best way was to use:

[OutputCache(Duration = 14400, VaryByParam = "*")]

And provide the parameters using redirect so that the defaults are used and cached content is shown.