IIS7 缓存控制 [英] IIS7 Cache-Control

查看:26
本文介绍了IIS7 缓存控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一些我认为相当简单的事情.让 IIS 7 告诉客户他们可以将我网站上的所有图像缓存一段时间,比如说 24 小时.

我已经尝试了 http://www.galcho.com/Blog/post/2008/02/27/IIS7-How-to-set-cache-control-for-static-content.aspx 但无济于事.我仍然收到发送到服务器的请求,并返回 304.

有没有人有办法做到这一点?我有一个图形密集型网站,我的用户每次请求页面时都会受到打击(我的服务器也是如此).奇怪的是,图像似乎在 Firebug 中显示Cache-Control private,max-age=3600",但当我按 F5 时浏览器仍在请求它们.

解决方案

如果您想设置 Cache-Control 标头,遗憾的是,IIS7 UI 中没有任何内容可以执行此操作.

但是,您可以将此 web.config 放在要设置它的文件夹或站点的根目录中:

<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00"/></staticContent></system.webServer></配置>

这将通知客户端将该文件夹和所有子文件夹中的内容缓存 7 天.

您也可以通过 appcmd.exe 编辑 IIS7 元数据库来执行此操作,如下所示:

<前>Windowssystem32inetsrvappcmd.exe设置配置默认网站/文件夹"-section:system.webServer/staticContent-clientCache.cacheControlMode:UseMaxAgeWindowssystem32inetsrvappcmd.exe设置配置默认网站/文件夹"-section:system.webServer/staticContent-clientCache.cacheControlMaxAge:"7.00:00:00"

I'm trying to do something which I thought would be fairly simple. Get IIS 7 to tell clients they can cache all images on my site for a certain amount of time, let's say 24 hours.

I have tried the step on http://www.galcho.com/Blog/post/2008/02/27/IIS7-How-to-set-cache-control-for-static-content.aspx but to no avail. I still get requests going to the server with 304s being returned.

Does anyone have a way of doing this? I have a graphically intensive site and my users are being hammered (so is my server) every time they request a page. Wierdly the images seem to have "Cache-Control private,max-age=3600" showing up in Firebug but the browser is still requesting them when I press F5.

解决方案

If you want to set the Cache-Control header, there's nothing in the IIS7 UI to do this, sadly.

You can however drop this web.config in the root of the folder or site where you want to set it:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
    </staticContent>
  </system.webServer>
</configuration>

That will inform the client to cache content for 7 days in that folder and all subfolders.

You can also do this by editing the IIS7 metabase via appcmd.exe, like so:

Windowssystem32inetsrvappcmd.exe 
  set config "Default Web Site/folder" 
  -section:system.webServer/staticContent 
  -clientCache.cacheControlMode:UseMaxAge

Windowssystem32inetsrvappcmd.exe 
  set config "Default Web Site/folder" 
  -section:system.webServer/staticContent 
  -clientCache.cacheControlMaxAge:"7.00:00:00"

这篇关于IIS7 缓存控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆