【问题标题】:IIS 7.5 Web.config file - Which caching directive has high priority?IIS 7.5 Web.config 文件 - 哪个缓存指令具有高优先级?
【发布时间】:2014-11-14 07:47:02
【问题描述】:

Asp.Net(无论是否为 MVC)Web 应用程序的 Web.config 文件通常在 system.webServer 部分下有两个缓存指令:

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

这一项将所有静态内容的缓存控制设置为 Max-Age: (Now+7Days)

同一部分下也有这个指令:

<caching>
    <profiles>
        <add extension=".jpg" location="Any" policy="CacheForTimePeriod" duration="7.00:00:00" kernelCachePolicy="CacheUntilChange" />
    </profiles>
</caching>

此指令将 .jpg 文件的缓存标头设置为过期:7 天,并为所有位置(代理、浏览器等)启用缓存

我不明白的是,哪个指令会覆盖另一个指令?如果我省略 .jpg 的配置文件,它会采用 clientCache 指令的值吗? (假设它由静态文件处理程序处理)

“kernelCachePolicy”实际上是做什么的?

【问题讨论】:

    标签: asp.net caching web-config iis-7.5


    【解决方案1】:

    首先,这个参数是给 IIS 的关于如何保存缓存的指令。

    静态内容缓存,使 IIS 自动添加客户端标头,并告诉浏览器将内容保留在其缓存中以及保留多长时间。

    静态内容是不变的内容,比如图片。

    <staticContent>
        <clientCache .... />
    </staticContent>
    

    您提到的第二个缓存是服务器端缓存。如果用于动态页面,最好使用它。它将呈现的页面保存在内存中,并在被询问时从那里提供。

    <caching>
        <profiles>
            <add .... />
        </profiles>
    </caching>
    

    你可以在这里阅读更多:What are difference between IIS (Dynamic and Static) cache,OutPutCache and browser cache

    也在 IIS 网站上。
    http://www.iis.net/configreference/system.webserver/staticcontent/clientcache
    http://www.iis.net/configreference/system.webserver/caching

    【讨论】:

    • 感谢@Aristos 的回答。我认为这意味着它们不会相互交互(或相互覆盖)。由于 MVC 没有扩展,因此 outputCache 是它的缓存,缓存配置文件用于特殊情况。
    • @Alaminut 是的,它们不会相互覆盖。我个人的意见是在web.config上使用仅静态内容缓存设置,动态缓存使用asp.net编程,可以编程控制。
    猜你喜欢
    • 2012-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-08
    • 1970-01-01
    • 1970-01-01
    • 2018-09-07
    • 2014-03-10
    相关资源
    最近更新 更多