0

Is there anyway to disable cache on a action of a returned view? By using an attribute or something? The reason for this is that IE9 and below seem to always cache my views/partial views, so I'd like to prevent that for some actions

2
  • Do you mean browser cache or server cache?
    – jorgebg
    Commented Jan 20, 2012 at 13:16
  • Both! I think i've done it with browser cache using JQuery, but Server cache is what I want to disable
    – CallumVass
    Commented Jan 20, 2012 at 14:23

1 Answer 1

4

Putting this attribute on an action should do the trick:

[System.Web.Mvc.OutputCache(NoStore = true, Duration = 0)]
7
  • It tells me that duration must be a positive number, so should I just set it to 1? Cache of 1 second should be fine i think?
    – CallumVass
    Commented Jan 20, 2012 at 13:21
  • 2
    +1 I edited the post, NoStore instead of VaryByParam. Hope you don't mind.
    – jgauffin
    Commented Jan 20, 2012 at 13:23
  • @BiffBaffBoff: 0 means that no cache should be used.
    – jgauffin
    Commented Jan 20, 2012 at 13:23
  • @jgauffin Not all! I've used [OutputCache(Duration=0, VaryByParam="None"] in the past and it worked for me, but after reading the MSDN docs, your solution actually makes more sense. Commented Jan 20, 2012 at 14:04
  • This doesnt work: System.InvalidOperationException: Duration must be a positive number. So I've set Duration = 1, 1 second shouldnt cause any harm
    – CallumVass
    Commented Jan 20, 2012 at 14:04

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.