3

I want to cache all my static content of mvc application.

I Added Web.config file like this in the Content folder enter image description here

I got proper response header from my server.

enter image description here

Even after receiving the header with max-age attribute, The next Request to the server goes with Cache-Control: no-cache

enter image description here

This again retrieve the whole data.

It is not caching.

I want to know What am i missing here. Thanks in advance.

Victor
  • 65
  • 7

1 Answers1

3

The no-cache in your screenshot is a request header not a response header.

It is likely being issued by your browser in response to you forcing a refresh (Control-F5). The browser is effectively saying 'please get me fresh data, I don't want the cached data'. The server-side can't control this - the client is the one making the request.

If you aren't forcing a refresh then you may have disabled your browser cache (e.g. https://stackoverflow.com/a/7000899/34092 ).

See also https://stackoverflow.com/a/14544664/34092 .

mjwills
  • 21,750
  • 6
  • 36
  • 59
  • Yes no-cache in my screenshot is a request header. But My Browser asks for the data even after the server set its response header(max-age=3600). – Victor Jun 07 '17 at 12:48
  • 1
    The browser is allowed to do that. You ultimately can't stop it doing that. Think of cache headers as 'hints' for the browser - it doesn't have to pay attention to them. Have you perhaps disabled the cache on your browser (e.g. https://stackoverflow.com/a/7000899/34092)? – mjwills Jun 07 '17 at 12:51
  • Then what might be reason for the browser asks for the data even after set its response header to max-age=3600 – Victor Jun 07 '17 at 12:54
  • 1
    The main two reasons are the ones I have mentioned. You force refreshed the page (Control-F5) or you disabled the cache in your browser. – mjwills Jun 07 '17 at 12:55
  • Thanks a lot. My Browser disabled cache when developer tool is Opened. – Victor Jun 07 '17 at 13:05