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?

2
  • 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 1, 2010 at 9: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. Oct 1, 2010 at 10:55

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.