IIS 不会缓存大 (76MB) 文件

IIS won't cache large (76MB) file

我似乎无法在 Windows 2012 R2 上获取 IIS 来缓存大型 .exe 文件。也就是说,当我不断请求文件时,我在资源监视器中看到文件被不断读取,运行

netsh http show cachestate

不显示缓存的文件。

我想我已经将系统配置为在内核中缓存文件夹的 .exe 文件并且没有最大文件大小。总缓存大小限制为 0,据我所知,这将使系统最多使用所有内存的一半。服务器有 6 GB RAM,其中有很多是免费的。

也就是说,在 Web 服务器根目录的输出缓存设置中:

我从配置为 4.0 ASP.NET 应用程序的虚拟文件夹提供文件。 4.6.2 已安装。虚拟文件夹指向同一系统上的 UNC 共享。 (我知道我可以指向本地文件系统;我正在模拟另一个系统上的托管文件。)

web.config 文件:

<?xml version="1.0" encoding="utf-8"?>
  <configuration>
  <system.webServer>
    <handlers>
      <clear />
      <add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
    </handlers>
    <caching>
      <profiles>
        <add extension=".txt" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" />
        <add extension=".exe" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" />
      </profiles>
    </caching>
  </system.webServer>
</configuration>

它将缓存小的 .txt 和 .exe 文件(每个大约 20 字节)。

我错过了什么阻止 IIS 缓存大文件?

As per the registry(UriMaxUriBytes ) which controls size of file which can be cached on the kernel is 16 MB.Also there are many scenarios in which http.sys will not cache the content.Please check this KB article instances-in-which-http-sys-does-not-cache-content

要使其正常工作 - 在以下注册表项下创建以下 DWORD 值:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\HTTP\Parameters

  • UriMaxUriBytes -UriMaxUriBytes 262144(字节)4096(4k) – 16777216(16MB) 字节 任何大于此值的响应都不会缓存在内核响应缓存中。 1个 3

  • UriScavengerPeriod - 确定缓存清道夫的频率。在等于 UriScavengerPeriod 的秒数内未被访问的任何响应或片段将被刷新。

您还可以调整 UriMaxCacheMegabyteCount(指定内核模式缓存可用的最大内存。)默认情况下为零 http.sys 来决定,但您可以给出一个高值

所以你可以

  1. 设置 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\HTTP\Parameters\UriMaxUriBytes 至 16777216
  2. 从文件小于 16 MB 的非 UNC 目录检查
  3. 没有对此请求进行身份验证或没有为此 mime 类型启用动态压缩

可以在此找到更多详细信息 msdn and server performance tuning

希望对您有所帮助!