Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to use the OutputCache attribute in my MVC app and it doesn't appear to work when I use OutputCacheLocation.Client:

public class HomeController : Controller
{
    [OutputCache(Duration=15, Location=OutputCacheLocation.Client)]
    public ActionResult Client()
    {
        ViewBag.Message = "The current time is " + DateTime.Now.ToString("hh:mm:ss");

        return View();
    } 

    [OutputCache(Duration=15, Location=OutputCacheLocation.Any)]
    public ActionResult Any()
    {
        ViewBag.Message = "The current time is " + DateTime.Now.ToString("hh:mm:ss");

        return View();
    }        
}

The first one does not cache. I hit the page every second and it changes the time. The second one works. It only changes the time every 15 seconds. Is there something I am missing? I'm debugging this using IE8 and the built in development server in Visual Studio.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
266 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you hit F5 you are evicting the client cache. The way client cache is supposed to work is that you have links on the site pointing to the Client action from some other views and when the user clicks on those links the cached version will get served (assuming of course he does that in the interval for which the page is cached).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...