سؤال

I'm not sure what caused this, but our controller action use to cache its output but it no longer does:

[HttpGet]
[OutputCache(VaryByParam = "slug", Duration = 3600)]
public ContentResult Index(string slug)
{
    // each call to the page returns a new tick value
    var viewData = DateTime.Now.Ticks.ToString();
    return View(viewData);
}

Before, I could debug the page, put a break point inside the Index method and the first call to the page would trigger the breakpoint, and the subsequent calls would not. Now, every call to the page triggers the break point.

Even when I am running the site (not debugging), I can trace the SQL calls in the action, which should not be called after the first call.

I don't know when it stopped working, but we somewhat recently upgraded to .Net 4.0 and MVC 3.

Thanks so much.

EDIT

Here are the headers of the page response:

Cache-Control   public, no-cache="Set-Cookie", max-age=1296000
Content-Encoding    gzip
Content-Length  5414
Content-Type    text/html; charset=utf-8
Date    Wed, 18 Sep 2013 00:33:23 GMT
Expires Thu, 03 Oct 2013 00:33:20 GMT
Last-Modified   Wed, 18 Sep 2013 00:33:20 GMT
Server  Microsoft-IIS/7.5
Set-Cookie  tag=tech; expires=Thu, 19-Sep-2013 00:33:23 GMT; path=/
Vary    *
X-AspNet-Version    4.0.30319
X-AspNetMvc-Version 3.0
X-Powered-By    ASP.NET
هل كانت مفيدة؟

المحلول

The problem is that I was setting a cookie value in the controller action:

HttpContext.Response.Cookies.Add(myCookie);

Which changed the header from this:

Cache-Control: public, max-age=1295931

To this:

Cache-Control: public, no-cache="Set-Cookie", max-age=1296000

By commenting the line that was added the cookie, the page cached again.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top