클라이언트 캐시 <clientCache>

개요

<clientCache> 요소의 <staticContent> 요소는 IIS 7 이상에서 웹 클라이언트에 보내는 캐시 관련 HTTP 헤더를 지정합니다. 이 헤더는 웹 클라이언트 및 프록시 서버가 IIS 7 이상에서 반환하는 콘텐츠를 캐시하는 방법을 제어합니다.

예를 들어 httpExpires 특성은 콘텐츠가 만료되어야 하는 날짜와 시간을 지정하고 IIS 7 이상에서는 응답에 HTTP "Expires" 헤더를 추가합니다. httpExpires 특성의 값은 RFC 1123의 사양을 따르는 완전한 형식의 날짜 및 시간이어야 합니다. 예를 들면 다음과 같습니다.

2010년 1월 1일 금요일 12:00:00 GMT

참고

httpExpires 특성을 사용하려면 cacheControlMode 특성의 값을 UseExpires로 설정해야 합니다.

RFC(주석 요청) 2616의 HTTP 1.1 사양은 HTTP "Cache-Control" 헤더에 대해 가능한 몇 가지 값(예: "no-cache", "private", "public")을 지정합니다. 이러한 각 헤더 값을 통해 웹 클라이언트와 프록시 서버는 콘텐츠를 캐시해야 하는지 여부를 알 수 있습니다.

  • "no-cache" 헤더가 포함된 콘텐츠는 엔터티에서 캐시해서는 안 됩니다. - "프라이빗" 헤더가 포함된 콘텐츠는 프록시 서버에서 캐시해서는 안 되지만 웹 클라이언트에서 캐시할 수 있습니다. - "public" 헤더가 포함된 콘텐츠는 모든 엔터티에 의해 캐시될 수 있습니다.

    참고

    위의 목록은 포괄적이지 않습니다. "Cache-Control" 헤더로 지정할 수 있는 많은 추가 값이 있습니다.

콘텐츠에 대한 명시적 만료 시간을 지정하는 "max-age"와 같은 추가 지시문을 HTTP "Cache-Control" 헤더에 추가할 수 있습니다. IIS 7에서 "max-age" 지시문은 cacheControlMaxAge 특성을 통해 구성됩니다. "Expires" 및 "max-age" 설정은 다소 유사하지만 "max-age" 지시문은 "만료"보다 우선합니다.

참고

cacheControlMaxAge 특성을 사용하려면 cacheControlMode 특성의 값을 UseMaxAge로 설정해야 합니다.

HTTP 캐싱 헤더 및 날짜/시간 형식에 대한 자세한 내용은 다음 RFC(주석 요청) 문서를 참조하세요.

  • RFC 1123 - "인터넷 호스트에 대한 요구 사항 -- 애플리케이션 및 지원"
  • RFC 2616 - "하이퍼텍스트 전송 프로토콜 -- HTTP/1.1"

호환성

버전 참고
IIS 10.0 <clientCache> 요소가 IIS 10.0에서 수정되지 않았습니다.
IIS 8.5 <clientCache> 요소가 IIS 8.5에서 수정되지 않았습니다.
IIS 8.0 setEtag HTTP ETag 헤더를 계산하고 설정할지 여부를 지정하기 위해 특성이 추가되었습니다.
IIS 7.5 <clientCache> 요소가 IIS 7.5에서 수정되지 않았습니다.
IIS 7.0 <clientCache> 요소의 <staticContent> 요소는 IIS 7.0에서 도입되었습니다.
IIS 6.0 요소는 <clientCache> 다음 IIS 6.0 메타베이스 속성을 대체합니다.
  • CacheControlCustom
  • CacheControlMaxAge
  • CacheControlNoCache
  • HttpExpires

설치 프로그램

<clientCache> 요소의 <staticContent> 요소는 IIS 7 이상의 기본 설치에 포함됩니다.

방법

웹 사이트 또는 애플리케이션에 대한 캐시 만료 날짜를 구성하는 방법

  1. IIS(인터넷 정보 서비스) 관리자를 엽니다.

    • Windows Server 2012 또는 Windows Server 2012 R2를 사용하는 경우:

      • 작업 표시줄에서 서버 관리자 클릭하고 도구를 클릭한 다음 IIS(인터넷 정보 서비스) 관리자를 클릭합니다.
    • Windows 8 또는 Windows 8.1 사용하는 경우:

      • Windows 키를 누른 채로 문자 X를 누른 다음 제어판 클릭합니다.
      • 관리 도구를 클릭한 다음 IIS(인터넷 정보 서비스) 관리자를 두 번 클릭합니다.
    • Windows Server 2008 또는 Windows Server 2008 R2를 사용하는 경우:

      • 작업 표시줄에서 시작을 클릭하고 관리 도구를 가리킨 다음 IIS(인터넷 정보 서비스) 관리자를 클릭합니다.
    • Windows Vista 또는 Windows 7을 사용하는 경우:

      • 작업 표시줄에서 시작을 클릭한 다음 제어판 클릭합니다.
      • 관리 도구를 두 번 클릭한 다음 IIS(인터넷 정보 서비스) 관리자를 두 번 클릭합니다.
  2. 연결 창에서 캐싱을 사용하지 않도록 설정할 사이트, 애플리케이션 또는 디렉터리로 이동합니다.

  3. 창에서 HTTP 응답 헤더를 두 번 클릭합니다.
    H T T P 응답 헤더가 선택된 기본 웹 사이트 홈 창을 보여 주는 스크린샷

  4. HTTP 응답 헤더 창의 작업 창에서 일반 헤더 설정...을 클릭합니다.
    I S 관리자의 H T T P 응답 헤더 창을 보여 주는 스크린샷

  5. 일반 HTTP 응답 헤더 설정 대화 상자에서 웹 콘텐츠 만료 상자를 검사 특정 간격 또는 특정 시간에 만료되는 옵션을 선택한 다음 확인을 클릭합니다.
    일반 H T T P 응답 헤더 설정 대화 상자를 보여 주는 스크린샷. H T T P 유지를 사용하도록 설정이 선택되었습니다.
    일반 H T T P 응답 헤더 설정 대화 상자를 보여 주는 스크린샷. 웹 콘텐츠 만료 확인란 아래에서 After를 선택합니다.

웹 사이트 또는 애플리케이션에 대한 캐싱을 사용하지 않도록 설정하는 방법

  1. IIS(인터넷 정보 서비스) 관리자를 엽니다.

    • Windows Server 2012 또는 Windows Server 2012 R2를 사용하는 경우:

      • 작업 표시줄에서 서버 관리자 클릭하고 도구를 클릭한 다음 IIS(인터넷 정보 서비스) 관리자를 클릭합니다.
    • Windows 8 또는 Windows 8.1 사용하는 경우:

      • Windows 키를 누른 채로 문자 X를 누른 다음 제어판 클릭합니다.
      • 관리 도구를 클릭한 다음 IIS(인터넷 정보 서비스) 관리자를 두 번 클릭합니다.
    • Windows Server 2008 또는 Windows Server 2008 R2를 사용하는 경우:

      • 작업 표시줄에서 시작을 클릭하고 관리 도구를 가리킨 다음 IIS(인터넷 정보 서비스) 관리자를 클릭합니다.
    • Windows Vista 또는 Windows 7을 사용하는 경우:

      • 작업 표시줄에서 시작을 클릭한 다음 제어판 클릭합니다.
      • 관리 도구를 두 번 클릭한 다음 IIS(인터넷 정보 서비스) 관리자를 두 번 클릭합니다.
  2. 연결 창에서 캐싱을 사용하지 않도록 설정할 사이트, 애플리케이션 또는 디렉터리로 이동합니다.

  3. 창에서 HTTP 응답 헤더를 두 번 클릭합니다.
    기본 웹 사이트 홈 창을 보여 주는 스크린샷 H T T P 응답 헤더가 선택되었습니다.

  4. HTTP 응답 헤더 창의 작업 창에서 일반 헤더 설정...을 클릭합니다.
    H T T P 응답 헤더 창을 보여 주는 스크린샷

  5. 일반 HTTP 응답 헤더 설정 대화 상자에서 웹 콘텐츠 만료 상자를 검사 즉시를 선택한 다음 확인을 클릭합니다.
    일반 H T T P 응답 헤더 설정 대화 상자를 보여 주는 스크린샷. 웹 콘텐츠 만료 확인란 아래에서 즉시 선택됩니다.

구성

특성

attribute Description
cacheControlCustom 선택적 문자열 특성입니다.

사용자 지정 HTTP 1.1 캐시 제어 지시문을 지정합니다.
cacheControlMaxAge 선택적 timeSpan 특성입니다.

캐시 제어 값의 최대 기간(초)을 지정합니다.

기본값은 (1일)입니다 1.00:00:00 .
cacheControlMode 선택적 열거형 특성입니다.

클라이언트 캐싱에 사용할 모드를 지정합니다.

cacheControlMode 특성은 다음과 같은 가능한 값 중 하나일 수 있습니다.

기본값은 NoControl입니다.
Description
NoControl 응답에 Cache-Control 또는 Expires 헤더를 추가하지 않습니다.

숫자 값은 입니다 0.
DisableCache Cache-Control: no-cache 헤더를 응답에 추가합니다.

숫자 값은 입니다 1.
UseMaxAge Cache-Control: max-age=<nnn> 헤더를 CacheControlMaxAge 특성에 지정된 값에 따라 응답에 추가합니다.

숫자 값은 입니다 2.
UseExpires httpExpires 특성에 지정된 날짜에 따라 Expires: <date> 헤더를 응답에 추가합니다.

숫자 값은 입니다 3.
httpExpires 선택적 문자열 특성입니다.

클라이언트에 캐시된 페이지가 부실한 것으로 간주되는 날짜 및 시간을 지정합니다. (날짜 및 시간은 설명 요청 1123의 사양에 따라 형식이 지정됩니다.) 값은 HTML 파일 헤더의 브라우저로 반환됩니다. 사용자 에이전트는 지정된 값을 현재 날짜와 비교하여 캐시된 페이지를 표시할지 아니면 서버에서 업데이트된 페이지를 요청할지 여부를 결정합니다.
setEtag 선택적 부울 특성입니다.

HTTP ETag 헤더를 계산하고 설정할지 여부를 지정합니다. ETag 헤더는 웹 캐시 유효성 검사에 사용되며, 콘텐츠가 변경되지 않은 경우 웹 서버가 전체 응답을 보낼 필요가 없도록 합니다. setEtag 는 경로 system.webServer/staticContent의 구성 편집기에서 설정할 수 있습니다.

기본값은 true입니다.

자식 요소

없음

구성 샘플

다음 구성 샘플에서는 HTTP "Cache-Control: no-cache" 헤더를 응답에 추가하여 요청 캐싱을 사용하지 않도록 설정합니다.

<configuration>
   <system.webServer>
      <staticContent>
         <clientCache cacheControlMode="DisableCache" />
      </staticContent>
   </system.webServer>
</configuration>

다음 구성 샘플에서는 HTTP "Expires: Tue, 19 Jan 2038 03:14:07 GMT" 헤더를 응답에 추가합니다. 이 헤더는 요청이 지금부터 몇 년 후에 만료되도록 구성합니다.

<configuration>
   <system.webServer>
      <staticContent>
         <clientCache cacheControlMode="UseExpires"
            httpExpires="Tue, 19 Jan 2038 03:14:07 GMT" />
      </staticContent>
   </system.webServer>
</configuration>

샘플 코드

다음 코드 샘플은 응답에 HTTP "Cache-Control: no-cache" 헤더를 추가하여 요청 캐싱을 사용하지 않도록 설정합니다.

AppCmd.exe

appcmd.exe set config "Default Web Site" -section:system.webServer/staticContent /clientCache.cacheControlMode:"DisableCache"

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using(ServerManager serverManager = new ServerManager())
      { 
         Configuration config = serverManager.GetWebConfiguration("Default Web Site");
         ConfigurationSection staticContentSection = config.GetSection("system.webServer/staticContent");

         ConfigurationElement clientCacheElement = staticContentSection.GetChildElement("clientCache");
         clientCacheElement["cacheControlMode"] = @"DisableCache";

         serverManager.CommitChanges();
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample

   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetWebConfiguration("Default Web Site")
      Dim staticContentSection As ConfigurationSection = config.GetSection("system.webServer/staticContent")

      Dim clientCacheElement As ConfigurationElement = staticContentSection.GetChildElement("clientCache")
      clientCacheElement("cacheControlMode") = "DisableCache"

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site";

var staticContentSection = adminManager.GetAdminSection("system.webServer/staticContent", "MACHINE/WEBROOT/APPHOST/Default Web Site");
var clientCacheElement = staticContentSection.ChildElements.Item("clientCache");
clientCacheElement.Properties.Item("cacheControlMode").Value = "DisableCache";

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site"

Set staticContentSection = adminManager.GetAdminSection("system.webServer/staticContent", "MACHINE/WEBROOT/APPHOST/Default Web Site")
Set clientCacheElement = staticContentSection.ChildElements.Item("clientCache")
clientCacheElement.Properties.Item("cacheControlMode").Value = "DisableCache"

adminManager.CommitChanges()

다음 코드 샘플은 HTTP "Expires: Tue, 19 Jan 2038 03:14:07 GMT" 헤더를 응답에 추가합니다. 이 헤더는 요청이 지금부터 몇 년 후에 만료되도록 구성합니다.

AppCmd.exe

appcmd.exe set config "Default Web Site" -section:system.webServer/staticContent /clientCache.cacheControlMode:"UseExpires"

appcmd.exe set config "Default Web Site" -section:system.webServer/staticContent /clientCache.httpExpires:"Tue, 19 Jan 2038 03:14:07 GMT"

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using(ServerManager serverManager = new ServerManager())
      { 
         Configuration config = serverManager.GetWebConfiguration("Default Web Site");
         ConfigurationSection staticContentSection = config.GetSection("system.webServer/staticContent");

         ConfigurationElement clientCacheElement = staticContentSection.GetChildElement("clientCache");
         clientCacheElement["cacheControlMode"] = @"UseExpires";
         clientCacheElement["httpExpires"] = @"Tue, 19 Jan 2038 03:14:07 GMT";

         serverManager.CommitChanges();
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample

   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetWebConfiguration("Default Web Site")
      Dim staticContentSection As ConfigurationSection = config.GetSection("system.webServer/staticContent")

      Dim clientCacheElement As ConfigurationElement = staticContentSection.GetChildElement("clientCache")
      clientCacheElement("cacheControlMode") = "UseExpires"
      clientCacheElement("httpExpires") = "Tue, 19 Jan 2038 03:14:07 GMT"

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site";

var staticContentSection = adminManager.GetAdminSection("system.webServer/staticContent", "MACHINE/WEBROOT/APPHOST/Default Web Site");
var clientCacheElement = staticContentSection.ChildElements.Item("clientCache");
clientCacheElement.Properties.Item("cacheControlMode").Value = "UseExpires";
clientCacheElement.Properties.Item("httpExpires").Value = "Tue, 19 Jan 2038 03:14:07 GMT";

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site"

Set staticContentSection = adminManager.GetAdminSection("system.webServer/staticContent", "MACHINE/WEBROOT/APPHOST/Default Web Site")
Set clientCacheElement = staticContentSection.ChildElements.Item("clientCache")
clientCacheElement.Properties.Item("cacheControlMode").Value = "UseExpires"
clientCacheElement.Properties.Item("httpExpires").Value = "Tue, 19 Jan 2038 03:14:07 GMT"

adminManager.CommitChanges()