1

In ASP.NET MVC, if I don't put a [Duration=x, VaryByParam="None"] attribute on my partial view, or if I put it with Duration=0, I sometimes get the error "Duration must be a positive number". I have read many posts on this topic, and they all seem to say that including the attribute with a non-zero duration is the only way to avoid that error.

But I do NOT want the data cached at all (not even for 1 second), and it seems to me that setting a non-zero cache duration would almost by definition be enabling caching (for whatever length of time I specify for the Duration).

All the posts I've read seem to ignore that, and talk about setting an attribute with a Duration as the way to avoid caching, but that doesn't make any sense to me. How can I completely avoid caching on a particular partial view? Also, is there a way to disable caching across my entire ASP.NET MVC application?

abatishchev
  • 92,232
  • 78
  • 284
  • 421
user756366
  • 405
  • 3
  • 18
  • 1
    You can avoid server-side caching by simply not applying an [OutputCache] attribute on its respective action. Are you talking about server-side output caching or client-side (browser) caching? – danludwig Aug 01 '12 at 12:18
  • If I skip the attribute, my popups don't refresh when the underlying data changes. It seems to cache by default. I don't know how to verify whether the caching is occurring client side or server side, though I've assumed it was client side. If I include the attribute, that fixes the popup refresh issue, but then I start getting the "Duration must be a positive number" errors in certain scenarios. I have not been able to see a pattern in when I do vs do not get the "Duration..." error - I only know that in some loading scenarios the attribute fixes things and in others, it causes exception. – user756366 Aug 01 '12 at 14:41
  • Sounds like client-side caching to me. You should be able to get around this with a cache-control header, or by appending something unique to the querystring, like so: /request/for/resource?when=[fill this in with current date and time so that client will not cache] – danludwig Aug 01 '12 at 15:03

2 Answers2

1

You should set a NoCache attribute if don't want to cache. Look at this answer: https://stackoverflow.com/a/1705113/2385

Community
  • 1
  • 1
Eduardo Molteni
  • 37,007
  • 23
  • 135
  • 201
0

Thanks all for your input. The comments about the issue being client-side were helpful. In the end, it turned out the issue was due to ajax caching being enabled by default in Internet Explorer. The solution was to disable that caching with a JQuery call as follows:

$.ajaxSetup({ cache: false });
arrowd
  • 30,130
  • 7
  • 72
  • 96
user756366
  • 405
  • 3
  • 18