3

I'm well aware of how I could set it myself, but I am concerned about having it configured in two different places. To receive the bounty, please tell me where I should look to find the existing setting.

Places we've already looked for the existing setting, without success:

  • the web.config <StaticContent> section
  • IIS output caching section, at all three levels:
    • machine
    • site
    • application
  • Code (I did a global search for SetMaxAge)

Context

We recently noticed that our CSS and JS files aren't getting refreshed. When I inspect the network traffic, they are coming back from the server with a header (Cache-Control: max-age=604800) that gives them a seven-day lifespan.

We need to reduce the cache lifetime. But for the life of me I can't find where it is set.

It is not set in the web.config <StaticContent> section.

It is not set in the IIS output caching section (I looked under the machine, the site, and the application-- they are all blank).

It is not set in code-- I did a global code search for SetMaxAge and got nuthin'. Where else can I look?

Is it possible it is being set by the gateway or load balancer in our data center?

John Wu
  • 50,556
  • 8
  • 44
  • 80
  • Adding a new setting for max age will either override the existing, or provides a duplicate header. Either way, it might tell you a lot about where it's getting set. – jpaugh Jun 06 '17 at 22:30
  • BTW, since the only answer-er was confused about your question, I've put the main question first. I'm hoping for a comprehensive answer, myself. – jpaugh Jun 06 '17 at 22:33
  • 1
    Thanks for that... I never did get an answer, and we did a workaround. But I still want to know, so I'm adding a bounty. – John Wu Jun 06 '17 at 22:45
  • Did you check web.config at the server and folder (js/css) levels? – mikep Jun 13 '17 at 04:08
  • Are there any headers indicating there could be a reverse proxy (X-Cache, Via, etc...). Varnish could do this... – Antony Gibbs Jun 13 '17 at 21:17

1 Answers1

4

You can do like this in web config, or you can use IIS ui to change (see link below):

<configuration>
  <system.webServer>
    <staticContent>
       <clientCache cacheControlMode="UseMaxAge"
        cacheControlMaxAge="1.00:00:00" /> <!-- 1 day -->
    </staticContent>
  </system.webServer>
</configuration>

See more here: https://www.iis.net/configreference/system.webserver/staticcontent/clientcache

IIS documentation states that the default value is 1 day.

Here are some other ways what could have affect these settings: http://www.galcho.com/blog/post/2008/02/27/IIS7-How-to-set-cache-control-for-static-content.aspx

  • overrideModeDefault value in applicationHost.config
  • earlier appcmd.exe settings
  • or client setting can also override your values.
DDan
  • 8,068
  • 5
  • 33
  • 52
  • I'm not sure adding it like this is the best idea when I don't know where the header is coming from to begin with. 7 days is not the default. If I add it here, I can't be sure it won't be overridden by whatever mechanism is currently putting it there. – John Wu Nov 09 '16 at 02:05
  • Where and how are you viewing the headers? – DDan Nov 09 '16 at 02:13
  • IIS documentation states that the default value is 1 day. I don't know how are you getting 7 – DDan Nov 09 '16 at 02:51
  • Neither do I! That is the point. The resources are coming back with `Cache-Control: max-age=604800` (7 days) which is definitely not the default. – John Wu Nov 09 '16 at 02:53
  • @JohnWu You can always put a `` under `` as first child node to clear inherited settings. Also, I recommend you to [enable failed request tracing logs](https://learn.microsoft.com/en-us/iis/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis#enable-failed-request-tracing) to see what happens. You can configure to collect data for `200 OK` responses ... – Kul-Tigin Jun 11 '17 at 00:20
  • @JohnWu ... After the logs created open the log named something like `fr000001.xml` with Internet Explorer skip Compact View and search for `HeaderName="Cache-Control"` as you can see in [this screenshot](https://i.stack.imgur.com/oQkce.png). If you can't see any `max-age=604800`, then you can suspect something on the network adds / replaces the header. – Kul-Tigin Jun 11 '17 at 00:20