【问题标题】:Cache configuration ASP.NET缓存配置 ASP.NET
【发布时间】:2019-06-11 02:51:26
【问题描述】:

我正在尝试了解以下缓存配置:

<!--Configures expiration for files in CMS/VPP-->
<staticFile expirationTime="12:0:0" />

<!--Configures expiration in IIS-->
<system.webServer>
   <!--Configures client headers for static files from IIS-->
   <staticContent>
       <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00"></clientCache>
   </staticContent>
   <!--Configures output and kernel caching for ALL images (both CMS and IIS)-->
   <caching>
      <profiles>
        <add extension=".gif" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
        <add extension=".png" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
        <add extension=".js" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
        <add extension=".css" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
        <add extension=".jpg" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
        <add extension=".jpeg" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
      </profiles>
   </caching>
</system.webServer>
</configuration>

因此静态文件将被缓存 1 天,为 cacheControlMaxAge="1.00:00:00"。但我很困惑为什么我们有:

<staticFile expirationTime="12:0:0" />

而且 mime 类型的有效期为 1 分钟:

<caching>
      <profiles>
        <add extension=".gif" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
        <add extension=".png" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
        <add extension=".js" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
        <add extension=".css" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
        <add extension=".jpg" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
        <add extension=".jpeg" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
      </profiles>
   </caching>

这是否意味着所有静态内容都缓存了 1 天,还是特定于设置?就像除 mime 类型之外的任何文件一样,mime 类型为 1 天,mime 类型为 1 分钟。

【问题讨论】:

    标签: asp.net asp.net-mvc caching


    【解决方案1】:

    &lt;staticFile&gt; 是非标准的。这似乎是EPiServer.Web.StaticFileHandler 的配置元素。 &lt;system.webServer&gt; 正在配置 IIS。使用哪种配置取决于处理请求的模块。

    https://docs.microsoft.com 的文档非常好:https://docs.microsoft.com/en-us/iis/configuration/system.webserver/staticcontent/clientcache

    除此之外,我想说没有比试一试更好的方法来找出它的作用/配置的重要性。在大多数浏览器上,您可以按 F12 并打开 developer tools。向静态文件发出请求并查看“网络”选项卡。读取响应头,如Cache-Control、Last-Modified等

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-22
      • 1970-01-01
      • 2016-05-29
      • 2015-07-30
      • 2022-07-03
      • 2013-12-03
      相关资源
      最近更新 更多