다음을 통해 공유


Azure 관리 캐시 서비스의 ASP.NET 페이지 출력 캐시 공급자 구성 설정

중요

모든 새 개발에서는 Azure Redis Cache를 사용하는 것이 좋습니다. Azure Cache 제품을 선택하는 방법에 대한 현재 설명서 및 지침 은 나에게 적합한 Azure Cache 제품을 참조하세요.

이 항목에서는 ASP.NET 대한 Azure Managed Cache Service 출력 캐시 공급자의 구성 설정에 대해 설명합니다. 이러한 설정은 web.config 파일에서 outputCache 요소의 공급자 섹션에 지정됩니다.

출력 캐시 구성 설정

attribute 설명

이름 (필수)

outputCache 요소가 공급자를 참조하는 데 사용하는 공급자의 "친숙한" 이름입니다.

형식 (필수)

공급자에 대한 .NET Framework 형식 문자열입니다. 필수 값은 아래의 참고 사항을 참조하세요.

cacheName (필수)

Azure 캐시의 이름입니다. “default”으로 설정해야 합니다.

dataCacheClientName (선택 사항)

dataCacheClients 구성 섹션에서 사용할 dataCacheClient 섹션의 이름입니다. 이 특성은 여러 dataCacheClient 섹션이 web.config 파일에 지정된 경우에만 필요합니다. 기본적으로 공급자는 dataCacheClient 섹션을 “default”사용합니다.

applicationName (선택 사항)

출력 캐시 데이터를 저장할 캐시 키를 만들 때 공급자가 사용하는 문자열 값입니다. 기본값은 빈 문자열입니다. 이 특성을 설정하지 않으면 공급자는 내부적으로 사용하는 캐시 키의 일부로 HttpRuntime.AppDomainAppId 값을 사용합니다. 세션 상태 기능과 달리 여러 ASP.NET 응용 프로그램에서 출력 캐시 데이터를 공유할 수 없습니다(예: /contoso와 /AdventureWorks에서 출력 캐시 데이터를 공유할 수 없음). 대신 같은 응용 프로그램의 여러 실제 인스턴스에서 모두 동일한 출력 캐시 데이터에 액세스할 수 있어야 합니다. 이 작업을 수행하는 방법에는 두 가지가 있습니다.

  • applicationName 공급자 특성이 명시적으로 설정되지 않은 경우 HttpRuntime.AppDomainAppId는 캐시 키를 생성할 때 공급자가 내부적으로 사용합니다. 즉, 정확히 같은 메타베이스 경로를 사용하여 같은 응용 프로그램의 각 실제 인스턴스(즉, /contoso 응용 프로그램을 호스팅하는 각 웹 서버)를 IIS에 설치해야 합니다. 메타베이스 경로가 SQL Server 및 out-of-process 세션 상태 공급자와 함께 사용되는 방법에 대한 설명을 참조https://support.microsoft.com/kb/325056하세요. 세션 상태는 다른 기능이지만 메타베이스 경로를 동기화 상태로 유지하는 것과 동일한 문제가 있습니다. 이는 applicationName 특성이 web.config 파일에 설정되지 않은 경우 출력 캐싱에 적용됩니다.

  • 더 쉬운 방법은 동일한 ASP.NET 애플리케이션의 각 인스턴스(예: /contoso 애플리케이션을 호스팅하는 각 웹 서버)가 web.config 파일에서 동일한 applicationName 특성을 사용하는 것입니다. 이렇게 하면 같은 응용 프로그램의 서로 다른 실제 인스턴스에서 동일한 출력 캐시 데이터를 읽고 쓸 수 있습니다. 이 경우 공급자는 캐시 키를 생성할 때 AppDomainAppId 를 사용하지 않으므로 메타베이스 경로가 일치하지 않을 위험이 없습니다.

retryInterval (선택 사항)

캐시와 통신할 때 오류가 발생한 경우 다시 시도 간에 대기할 시간 길이에 대한 TimeSpan입니다. 이 값에 사용할 문자열 형식은 "HH:MM:SS"입니다. 기본적으로 공급자는 1초 동안 대기합니다.

retryCount (선택 사항)

캐시와의 통신 실패 시 공급자에 다시 시도 횟수를 알려 주는 정수 값입니다. 일부 작업은 다시 시도할 수 없습니다. 다시 시도 횟수 기본값은 3회입니다. 공급자는 각 재시도 사이에 구성된 retryInterval 시간 동안 절전 모드로 전환됩니다.

참고

형식 특성을 .로 설정“Microsoft.Web.DistributedCache.DistributedCacheOutputCacheProvider, Microsoft.Web.DistributedCache”해야 합니다.

예제

<!-- Non-cache sections omitted for space -->
<configuration>
  <configSections>
    <section name="dataCacheClients" 
        type="Microsoft.ApplicationServer.Caching.DataCacheClientsSection, Microsoft.ApplicationServer.Caching.Core" 
        allowLocation="true" 
        allowDefinition="Everywhere" />
    <section name="cacheDiagnostics" 
        type="Microsoft.ApplicationServer.Caching.AzureCommon.DiagnosticsConfigurationSection, Microsoft.ApplicationServer.Caching.AzureCommon" 
        allowLocation="true" 
        allowDefinition="Everywhere" />
  </configSections>
  <system.web>
    <!-- Azure Caching output caching provider -->
    <!--Uncomment this section to use Azure Caching for output caching-->
    <caching>
      <outputCache defaultProvider="AFCacheOutputCacheProvider">
        <providers>
          <add name="AFCacheOutputCacheProvider" 
            type="Microsoft.Web.DistributedCache.DistributedCacheOutputCacheProvider, Microsoft.Web.DistributedCache"
            cacheName="default"
            dataCacheClientName="default"
            applicationName="AFCacheOutputCache" />
        </providers>
      </outputCache>
    </caching>
  </system.web>
  <dataCacheClients>
    <dataCacheClient name="default">
      <!--To use the in-role flavor of Azure Caching, set identifier to be the cache cluster role name -->
      <!--To use the Azure Caching Service, set identifier to be the endpoint of the cache cluster -->
      <autoDiscover
        isEnabled="true" 
        identifier="[Cache role name or Service Endpoint]" />
      <!--<localCache isEnabled="true" sync="TimeoutBased" objectCount="100000" ttlValue="300" />-->
      <!--Use this section to specify security settings for connecting to your cache. 
          This section is not required if your cache is hosted on a role that is a part 
          of your cloud service. -->
      <!--<securityProperties mode="Message" sslEnabled="false">
        <messageSecurity authorizationInfo="[Authentication Key]" />
      </securityProperties>-->
    </dataCacheClient>
    <cacheDiagnostics>
      <crashDump dumpLevel="Off" dumpStorageQuotaInMB="100" />
    </cacheDiagnostics>
  </dataCacheClients>
</configuration>

참고

cacheDiagnostics 섹션은 캐시 NuGet 패키지를 통해서만 ASP.NET 웹 역할 클라이언트에 추가됩니다. 자세한 내용은 Azure Managed Cache Service ClientDiagnosticLevel 정보를 참조하세요.

참고 항목

개념

Azure 관리 캐시 서비스의 페이지 출력 캐시 공급자