Feb 18, 2015 at 4:55 PM
Edited Feb 18, 2015 at 4:56 PM
I have an implementation where caching should be disabled completely if someone has a certain cookie in their request. I want to use VaryByCustom to achieve this.

My cacheProvider is configured in the web.config like this:

<add name="MyCacheProfile" duration="60" enabled="true" varyByCustom="SessionPreview" varyByParam="*" location="Server" />

In the global.asax.cs I have overridden GetVaryByCustomString as explained here:
I can see in my log file that this method is called and works as expected.

Unfortunately, the result is not what I want. I still get a cached version of the page. If, on the other hand, I set 'enabled' to 'false', I get an uncached version. This means that 'MyCacheProfile' is indeed used.

Is there a reason why VaryByCustom should not work in combination with mvcdonutcaching?
Or is there another way to dynamically disable the output caching?