IIS 输出缓存功能可将全部响应缓存在内存中,甚至是动态内容的响应。 与 IIS 6.0 中的缓存不同,IIS 7.0 及更高版本中的缓存是“智能的”,站点所有者和开发人员可将输出缓存配置为基于查询字符串值缓存单独的响应副本。 输出缓存还与 HTTP.sys 内核缓存集成,有助于提升性能。 内核缓存默认未锁定。 开发人员可在其应用程序中配置缓存配置文件来利用此功能。 可运行命令行工具来显示 HTTP.sys 缓存中的内容。
使用 netsh 查看 HTTP 响应缓存
- 打开命令提示符并运行以下命令:
netsh http show cache
使用 IIS PowerShell 提供程序启用缓存
- 打开 PowerShell 提示符并键入以下内容:
set-webconfigurationproperty /system.webServer/caching iis:\sites\mysite -name enabled -value true
使用 IIS PowerShell 提供程序添加新项
- 添加额外属性哈希 -value @{...}
add-webconfigurationproperty /system.webServer/caching iis:\sites\mysite `-name profiles `-value @{extension='.tif'; policy='CacheForTimePeriod';duration='00:00:10'}
更改缓存项的设置
- 获取特定项:
$cacheEntry = get-webconfigurationproperty /system.webServer/caching iis:\sites\mysite -atElement @{extension='.tif'}
- 更改属性
$cacheEntry.Duration = [TimeSpan]::FromSeconds(10)
$cacheEntry.kernelCachePolicy = 'CacheForTimePeriod'
set-webconfigurationproperty /system.webServer/caching iis:\sites\mysite `
-name profiles `
-atElement @{extension='.tif'} `
-value $cacheEntry