1

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?

gmakrygiannis
  • 360
  • 3
  • 14
  • Can you elaborate on "the content is not cached properly"? What results are you seeing, and how exactly do they differ from your expectations? – bzlm Oct 01 '10 at 09:26
  • Sorry, I should be more clear about that. What I mean is that the content is not retrieved from cache it's created again for each request. – gmakrygiannis Oct 01 '10 at 10:55

1 Answers1

0

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.

gmakrygiannis
  • 360
  • 3
  • 14