1

Can someone please shed some light into this? An action is decorated this way:

 [OutputCache(Duration = 5, VaryByParam = "none")]
        public ActionResult MyAction()
{
// DO STUFF HERE...
}

The MyAction invokes a view which has a form (which posts back to the MyAction POSTED-Method). The mechanism (of posting back) works fine. I declare Duration 5, meaning 5 seconds (or not?). So after 5 seconds if call it again

http://myAddress/MyController/MyAction

. . . the action is not called! Why? What am i missing? Thanks in advance!

3 Answers 3

1

Try to rule out client-side caching. (Clear the cache in your browser, or use a different browser, add a dummy parameter etc.) Your browser is more likely to cache this content than non-output-cached pages because MVC actually sends a suggestion to the client to cache the content for the specified time. I wouldn't be surprised if your browser took that suggestion and decided to cache longer than suggested.

At what point does your server-side code trigger again? 20 seconds? 40? ever?

Sign up to request clarification or add additional context in comments.

3 Comments

To be honest i also think it has to do with client side caching. So i cleared the cache (in Mozilla FireFox) and called immediately myAddress/MyController/MyAction with the same result (the action doesn't get called)
I think your suggestion would be the closest solution to this kind of problems. So i take it as a solution.Thanks.
@sawas Does it ever call the action method again? 5 minutes later?
0

If you want to test the OutputCache attribute it is very easy to do so:

Controller: public class HomeController : Controller { [OutputCache(Duration=60)] public ActionResult Index() { ViewBag.Time = DateTime.Now; } }

View:

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>@ViewBag.Time</p>

If you compile this an go to the home action, it will display the current time. If you refresh it, then it won't update for another 60 seconds.

On another note, I'm not sure you understand the VaryByParam parameter. This will mean that it will cache separate versions for the "none" query parameter.

That means if you have the following URLs:

/home/index
/home/index?none=abc
/home/index?none=xyz

They will all be cached separately from each other. Maybe you did understand this, but I was interpreting your "none" to mean that you didn't want it to vary by parameter and that's why you put "none" in there. If I misunderstood your intention then just ignore this part.

Comments

0

Turns out that this behavior resulted from false logic inside the Action Method. Debugging in Firebug showed the following:

Server  ASP.NET Development Server/10.0.0.0
Date    Mon, 17 Oct 2011 18:23:46 GMT
X-AspNet-Version    4.0.30319
X-AspNetMvc-Version 3.0
Cache-Control   no-cache, no-store, must-revalidate
Pragma  no-cache
Expires -1
Content-Type    text/html; charset=utf-8
Content-Length  7057
Connection  Close

which (i think) is the correct behavior! Thanks everybody for helping!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.