2

I have a MVC4/Razor website. The content is static for about a month or so - so no DB hits. Just FYI, it has Areas well.

How can I implement Caching for the entire application? Is there a way to add [OutputCache] attribute at a centralized location (say global.asax) rather than adding it to individual controllers?

parsh
  • 746
  • 1
  • 10
  • 23

1 Answers1

0

You can register the filter globally in Global.asax

var filters = GlobalFilters.Filters;
filters.Add(new MyOutputCacheFilter());
pollirrata
  • 5,188
  • 2
  • 32
  • 50
  • Maybe I am doing it wrong, I added the code to RegisterGlobalFilters() // Registering the ouputcache filter for entire app. OutputCacheAttribute outputCache = new OutputCacheAttribute { Location = System.Web.UI.OutputCacheLocation.Server, Duration = 86400, VaryByParam = "none", }; filters.Add(outputCache); In firebug, i see this Cache-Control no-cache . Expires -1 And under Cache Tab i see this Expires Wed Dec 31 1969 16:00:00 Sorry If i am missing something. – parsh Apr 15 '13 at 22:26
  • what .net version do you have? – pollirrata Apr 15 '13 at 22:29
  • Check this answer to see if it helps... http://stackoverflow.com/a/12052398/1242985 – pollirrata Apr 15 '13 at 22:30
  • Hmm nope. It looks like I had to set outputCacheLocation = ServerAndClient to make it work. – parsh Apr 18 '13 at 03:39