OutputCache Location=Client does not appear to work

Dismissile picture Dismissile · Mar 6, 2012 · Viewed 9.3k times · Source

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.

Answer

Darin Dimitrov picture Darin Dimitrov · Mar 7, 2012

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).