ETags、IIS7、内核缓存策略(enableKernelCache)

发布于 2024-08-15 23:57:12 字数 1853 浏览 13 评论 0原文

由两部分组成的问题(各部分密切相关):使用 IIS7 采用的默认 OOTB ETag 策略,为什么我们在浏览页面时看不到 If-None-Match/304 交互?

例如,为空缓存请求返回的标头是:

Content-Type    image/png
Last-Modified   Thu, 03 Dec 2009 15:51:56 GMT
Accept-Ranges   bytes
Etag    "a8a0628a3074ca1:0"
Server  Microsoft-IIS/7.0
X-Powered-By    ASP.NET
Date    Tue, 22 Dec 2009 19:47:36 GMT
Content-Length  1780

...但随后对该页面的访问不会为图像生成 304 往返?

另外,IIS7 的默认 applicationHost 文件具有以下 (1) 内容:

   <caching enabled="true" enableKernelCache="true">
   </caching>

enableKernelCache='true' 是否扩展到所有静态文件,使您无需显式注册扩展授予 CacheUntilChange 作为内核策略 (2):

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

(1) %systemroot%\System32\inetsrv\config\applicationHost.config

(2) http://labs.episerver.com/en/Blogs/Per/Archive /2009/3/在 IIS-7 上配置缓存过期/

Two-part question (parts are closely related): with the default OOTB ETag policy that IIS7 employs, why don't we see the If-None-Match/304 interaction as we navigate through pages?

The headers returned for an empty-cache request, for instance, are:

Content-Type    image/png
Last-Modified   Thu, 03 Dec 2009 15:51:56 GMT
Accept-Ranges   bytes
Etag    "a8a0628a3074ca1:0"
Server  Microsoft-IIS/7.0
X-Powered-By    ASP.NET
Date    Tue, 22 Dec 2009 19:47:36 GMT
Content-Length  1780

...and yet subsequent accesses to the page don't generate a 304 round-trip for the image?

Also, the default applicationHost file for IIS7 has the following (1):

   <caching enabled="true" enableKernelCache="true">
   </caching>

Does enableKernelCache='true' extend to all static files, freeing you of the need to register extensions explicitly to grant CacheUntilChange as the kernel policy (2):

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

(1) %systemroot%\System32\inetsrv\config\applicationHost.config

(2) http://labs.episerver.com/en/Blogs/Per/Archive/2009/3/Configuring-cache-expiration-on-IIS-7/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终难愈 2024-08-22 23:57:12

ETag 和关联的 If-None-Match / If-Modified-Since 的处理在某种程度上依赖于浏览器。您可以尝试几种不同的浏览器,看看会发生什么 - 一般来说,如果您没有设置明确的过期时间,我希望看到 304,正如您所说。

对于内核缓存,默认情况下为静态文件启用。为了帮助了解发生的情况,我发现运行以下命令很有帮助:

netsh http show cachestate

这将显示有关当前缓存中的文件的信息。

请记住,文件通常必须在某个时间窗口内被引用几次,然后内核才会缓存它们。

The handling of ETags and the associated If-None-Match / If-Modified-Since is somewhat browser dependent. You might try a few different browsers and see what happens -- in general, if you don't set an explicit expiration time, I would expect to see the 304's, as you said.

For kernel caching, it is enabled for static files by default. To help see what's happening, I've found it helpful to run the following command:

netsh http show cachestate

That will show information about the files that are currently in the cache.

Keep in mind that files normally have to be referenced a couple of times within a certain time window before the kernel will cache them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文