Why is output caching not working for my ASP.NET MVC 4 app?

前端 未结 1 1893
攒了一身酷
攒了一身酷 2020-12-15 07:58

I am having an issue where output caching doesn\'t appear to be working for my ASP.NET MVC 4 (EPiServer 7) website.

I have the following output cache profile in my

相关标签:
1条回答
  • 2020-12-15 08:42

    So, it turns out that OutputCaching was working, it was just that my method of testing it was flawed. The result of an action will only be cached if the response doesn't include a cookie. Of course the first response always includes a cookie if you have ASP.NET Session enabled which we do. Therefore the first response headers look like this:

    HTTP/1.1 200 OK
    Cache-Control: private, max-age=600
    Content-Type: text/html; charset=utf-8
    Content-Encoding: gzip
    Expires: Tue, 26 Nov 2013 03:48:44 GMT
    Last-Modified: Tue, 26 Nov 2013 03:38:44 GMT
    Vary: *
    Set-Cookie: ASP.NET_SessionId=kbnhk4lphdlcpozcumpxilcd; path=/; HttpOnly
    X-UA-Compatible: IE=Edge
    Date: Tue, 26 Nov 2013 03:38:44 GMT
    Content-Length: 9558
    

    Assuming your browser or test tool can accept cookies and include those in the subsequent requests, the next request to the same page would result in HTTP response headers like so:

    HTTP/1.1 200 OK
    Cache-Control: private, max-age=598
    Content-Type: text/html; charset=utf-8
    Content-Encoding: gzip
    Expires: Tue, 26 Nov 2013 03:48:45 GMT
    Last-Modified: Tue, 26 Nov 2013 03:38:45 GMT
    Vary: *
    X-UA-Compatible: IE=Edge
    Date: Tue, 26 Nov 2013 03:38:45 GMT
    Content-Length: 9558
    

    As there is no client specific information in the response the output can now be cached as expected.

    So, lesson is when testing output caching use a testing tool that can accept and return cookies in subsequent requests.

    We ended up using Jmeter rather than tinyget and everything now works as expected.

    0 讨论(0)
提交回复
热议问题