Disable OutputCache on Development System
Asked Answered
R

2

17

I use OutputCache in an ASP.net MVC application. As developing with an active OutputCache is not very pleasant I want to disable the OutputCache on the Development Systems (local machines and development server).

What is the best way to do this?

Ritualism answered 7/5, 2010 at 12:7 Comment(1)
A newer duplicate question came up with an interesting answer for the situation when you want to alter some output caching but not all: use cache profiles.Odle
C
19

It's an old one but...

set this in your web.config under system.web

<caching>
  <outputCache enableOutputCache="false" />
</caching>
Chamness answered 14/1, 2011 at 16:56 Comment(2)
Shouldn't this be false instead of true?Nino
@TonyBasallo This really does not work on IIS Express 8.Why so ?Costanzia
F
15

The outputcache in ASP.NET can be enabled and disabled using

For iis versions < 7.0

<system.web>
    <caching>
        <outputCache enableOutputCache="false" />
    </caching>
</system.web>

For iis versions >= 7.0

<system.webServer>
    <caching enabled="false" />
</system.webServer>

N.B. I usually use both, better safe than having a sore foot, and use a config transform to make sure that the caching is enabled for different configurations on publish. In my solution a configuration corresponds 1 on 1 with an environment

Another technique is to use pragmas to enable pieces of code to compile or not compile based on i.e. the DEBUG conditional compilation symbol:

#if DEBUG
    [OutputCache]
#endif
Filefish answered 9/10, 2013 at 9:34 Comment(2)
The pre IIS 7 version is needed for IIS Express 8Rouleau
These two examples (pre & post IIS7), are for different functionalities. The example in <system.web> is for the ASP.NET OutputCache (learn.microsoft.com/en-us/iis/configuration/system.webserver/…). The example in <system.webServer> is for built-in IIS response caching (learn.microsoft.com/en-us/iis/configuration/system.webserver/…). IIS cache is interoperable with OutputCache.Urn

© 2022 - 2024 — McMap. All rights reserved.