web.config cache settings not working

2019-06-09 03:11发布

问题:

I want to enable cache for static contents of my website. I found this method using IIS cache control option which I guess it works serverside:

    <caching>
        <profiles>
            <add extension=".js" policy="CacheUntilChange" kernelCachePolicy="DontCache" />
            <add extension=".css" policy="CacheUntilChange" kernelCachePolicy="DontCache" />
        </profiles>
    </caching>

Also I found this solution for client side cache of static contents:

    <staticContent>
        <clientCache cacheControlMaxAge="7.00:00:00" cacheControlMode="UseMaxAge" />
    </staticContent>

After adding both of above codes, I have cleared history and used hard refresh. But when I check network tab in Chrome console, the loading time of static content are still in seconds (not from user cache). I have to say that the check box to disable cache is also unchecked in developer console.

Edit: After updating kernelCachePlicy to CacheUntilChange I have used netsh http show cachestate to check state of cache and this is a sample output, but the browser still loads file from server not from local cache.

URL: [PTAH TO A PNG FILE]
    Status code: 200
    HTTP verb: GET
    Cache policy type: User invalidates
    Creation time: 2017.11.1:20.41.18:0
    Request queue name: MyPool
    Content type: image/png
    Content encoding: (null)
    Headers length: 244
    Content length: 1507
    Hit count: 5
    Force disconnect after serving: FALSE