PartialCachingAttribute 클래스

정의

자신의 출력이 캐시되는 경우와 방법을 나타내기 위해 Web Forms 사용자 정의 컨트롤(.ascx 파일)이 사용하는 메타데이터 특성을 정의합니다. 이 클래스는 상속될 수 없습니다.

public ref class PartialCachingAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class)]
public sealed class PartialCachingAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class)>]
type PartialCachingAttribute = class
    inherit Attribute
Public NotInheritable Class PartialCachingAttribute
Inherits Attribute
상속
PartialCachingAttribute
특성

예제

다음 코드 예제에서는 .를 사용하는 방법을 PartialCachingAttribute보여 줍니다. 이 예제에는 다음 세 부분이 있습니다.

  • 기본 클래스 ctlMine에서 UserControl 상속되고 PartialCachingAttribute 특성이 적용되는 부분 클래스입니다.

  • partial 클래스와 함께 ctlMine 사용되는 사용자 컨트롤입니다.

  • 사용자 컨트롤을 호스트하는 Web Forms 페이지입니다.

예제의 첫 번째 부분에서는 기본 클래스에서 UserControl 상속되고 특성이 적용되는 부분 클래스를 PartialCachingAttribute 보여 줍니다. 이 예제에서 특성은 사용자 정의 컨트롤을 20초 동안 캐시해야 한다고 지정합니다.

// [filename partialcache.cs]
// Create a code-behind user control that is cached
// for 20 seconds using the PartialCachingAttribute class.
// This control uses a DataGrid server control to display
// XML data.
using System;
using System.IO;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Samples.AspNet.CS.Controls
{

    // Set the PartialCachingAttribute.Duration property to 20 seconds.
    [PartialCaching(20)]
    public partial class ctlMine : UserControl
    {

        protected void Page_Load(Object Src, EventArgs E)
        {
            DataSet ds = new DataSet();

            FileStream fs = new FileStream(Server.MapPath("schemadata.xml"), FileMode.Open, FileAccess.Read);
            StreamReader reader = new StreamReader(fs);
            ds.ReadXml(reader);
            fs.Close();

            DataView Source = new DataView(ds.Tables[0]);
            // Use the LiteralControl constructor to create a new
            // instance of the class.
            LiteralControl myLiteral = new LiteralControl();
            // Set the LiteralControl.Text property to an HTML
            // string and the TableName value of a data source.
            myLiteral.Text = "<h6><font face=verdana>Caching an XML Table: " + Source.Table.TableName + " </font></h6>";
            MyDataGrid.DataSource = Source;
            MyDataGrid.DataBind();

            TimeMsg.Text = DateTime.Now.ToString("G");
        }
    }
}
' Filename is partialcache.vb
' Create a code-behind user control that is cached
' for 20 seconds using the PartialCachingAttribute class.
' This control uses a DataGrid server control to display
' XML data.
Imports System.IO
Imports System.Data
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace Samples.AspNet.VB.Controls

    ' Set the PartialCachingAttribute.Duration property to 20 seconds.
    <PartialCaching(20)> _
    Partial Class ctlMine
        Inherits UserControl

        Protected Sub Page_Load(ByVal Src As [Object], ByVal E As EventArgs)
            Dim ds As New DataSet()

            Dim fs As New FileStream(Server.MapPath("schemadata.xml"), FileMode.Open, FileAccess.Read)
            Dim reader As New StreamReader(fs)
            ds.ReadXml(reader)
            fs.Close()

            Dim [Source] As New DataView(ds.Tables(0))
            ' Use the LiteralControl constructor to create a new
            ' instance of the class.
            Dim myLiteral As New LiteralControl()
            ' Set the LiteralControl.Text property to an HTML
            ' string and the TableName value of a data source.
            myLiteral.Text = "<h6><font face=verdana>Caching an XML Table: " & [Source].Table.TableName & " </font></h6>"
            MyDataGrid.DataSource = [Source]
            MyDataGrid.DataBind()

            TimeMsg.Text = DateTime.Now.ToString("G")
        End Sub
    End Class
End Namespace

예제의 두 번째 부분에서는 사용자 정의 컨트롤 캐싱을 보여 주는 이전 예제와 함께 사용되는 사용자 정의 컨트롤을 보여 줍니다.

<!-- The mark-up .ascx file that displays the output of
     the partialcache.cs user control code-behind file. -->
<%@ Control language="C#" inherits="Samples.AspNet.CS.Controls.ctlMine" CodeFile="partialcache.cs.ascx.cs" %>

  <ASP:DataGrid id="MyDataGrid" runat="server"
    Width="900"
    BackColor="#ccccff"
    BorderColor="black"
    ShowFooter="false"
    CellPadding="3"
    CellSpacing="0"
    Font-Names="Verdana"
    Font-Size="8pt"
    HeaderStyle-BackColor="#aaaadd"
    EnableViewState="false"
  />

  <br />

  <i>Control last generated on:</i> <asp:label id="TimeMsg" runat="server" />
<!-- The mark-up .ascx file that displays the output of
     the partialcache.vb user control code-behind file. -->
<%@ Control language="vb" inherits="Samples.AspNet.VB.Controls.ctlMine" CodeFile="partialcache.vb.ascx.vb" %>

  <ASP:DataGrid id="MyDataGrid" runat="server"
    Width="900"
    BackColor="#ccccff"
    BorderColor="black"
    ShowFooter="false"
    CellPadding="3"
    CellSpacing="0"
    Font-Names="Verdana"
    Font-Size="8pt"
    HeaderStyle-BackColor="#aaaadd"
    EnableViewState="false"
  />

  <br />

  <i>Control last generated on:</i> <asp:label id="TimeMsg" runat="server" />

예제의 세 번째 부분에서는 사용자 컨트롤을 호스트하는 Web Forms 페이지를 보여 줍니다.

<!-- The WebForms page that contains the user control generated
     by partialcache.cs. -->
<%@ Register TagPrefix="Acme" TagName="Cache" Src="partialcache.cs.ascx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<script language="C#" runat="server">

      void Page_Load(Object Src, EventArgs E ) {

          TimeMsg.Text = DateTime.Now.ToString("G");
      }

  </script>

<head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
  
  <form id="form1" runat="server">
    <Acme:Cache runat="server"/>
    <br />

    <i>Page last generated on:</i> <asp:label id="TimeMsg" runat="server" />

  </form>
</body>
</html>
<!-- The WebForms page that contains the user control generated
     by partialcache.vb. -->
<%@ Register TagPrefix="Acme" TagName="Cache" Src="partialcache.vb.ascx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<script language="vb" runat="server">

   Sub Page_Load(Src As [Object], E As EventArgs) 
      TimeMsg.Text = DateTime.Now.ToString("G")
   End Sub 'Page_Load

  </script>

<head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
  
  <form id="form1" runat="server">
    <Acme:Cache runat="server"/>
    <br />

    <i>Page last generated on:</i> <asp:label id="TimeMsg" runat="server" />

  </form>
</body>
</html>

설명

특성 클래스는 PartialCachingAttribute 조각 캐싱을 지원하는 사용자 컨트롤(.ascx 파일)을 표시하고 ASP.NET 컨트롤을 캐싱할 때 사용하는 캐시 설정을 캡슐화합니다. 페이지 및 컨트롤 개발자는 이 특성을 사용하여 PartialCachingAttribute 코드 숨김 파일에서 사용자 컨트롤에 대한 출력 캐싱을 사용하도록 설정합니다.

PartialCachingAttribute 이 방법을 사용하면 출력 캐싱을 사용하도록 설정할 수 있는 여러 가지 방법 중 하나입니다. 다음 목록에서는 출력 캐싱을 사용하도록 설정하는 데 사용할 수 있는 방법을 설명합니다.

  • 지시문을 @ OutputCache 사용하여 선언적 시나리오에서 출력 캐싱을 사용하도록 설정합니다.

  • PartialCachingAttribute 코드 숨김 파일에서 사용자 컨트롤에 대한 캐싱을 사용하도록 설정하는 데 사용합니다.

  • 클래스를 ControlCachePolicy 사용하여 인스턴스로 작업 BasePartialCachingControl 하는 프로그래밍 방식 시나리오에서 캐시 설정을 프로그래밍 방식으로 지정합니다.

사용자 컨트롤에 지시문이 포함되어 @ OutputCache 있거나 적용된 PartialCachingAttribute 경우 ASP.NET 파서는 클래스의 PartialCachingControl 인스턴스를 생성하여 사용자 컨트롤을 래핑합니다.

ASP.NET 캐싱에 대한 자세한 내용은 캐싱을 참조하세요. 특성을 사용 하는 방법에 대 한 자세한 내용은 참조 하세요. 특성합니다.

생성자

PartialCachingAttribute(Int32)

캐시될 사용자 정의 컨트롤에 할당된 특정 시간을 사용하여 PartialCachingAttribute 클래스의 새 인스턴스를 초기화합니다.

PartialCachingAttribute(Int32, String, String, String)

PartialCachingAttribute 클래스의 새 인스턴스를 초기화하여 캐시를 변경하는 데 사용되는 사용자 지정 출력 캐싱 요구 사항, 캐싱 기간, GET 및 POST 값 및 컨트롤 이름을 지정합니다.

PartialCachingAttribute(Int32, String, String, String, Boolean)

PartialCachingAttribute 클래스의 새 인스턴스를 초기화하여 캐싱 기간, GETPOST 값, 컨트롤 이름, 사용자 정의 컨트롤을 변경하는 데 사용되는 사용자 지정 출력 캐싱 요구 사항 및 사용자 정의 컨트롤 출력을 여러 페이지에서 공유할 수 있는지 여부를 지정합니다.

PartialCachingAttribute(Int32, String, String, String, String, Boolean)

PartialCachingAttribute 클래스의 새 인스턴스를 초기화하여 캐싱 기간, GETPOST 값, 컨트롤 이름, 사용자 정의 컨트롤을 변경하는 데 사용되는 사용자 지정 출력 캐싱 요구 사항, 데이터베이스 종속성 및 사용자 정의 컨트롤 출력을 여러 페이지에서 공유할 수 있는지 여부를 지정합니다.

속성

Duration

출력 캐시에 캐시된 항목을 보관해야 하는 시간(초)을 가져옵니다.

ProviderName

연결된 컨트롤에 대한 출력 캐시된 데이터를 저장하는 데 사용되는 공급자의 이름을 가져오거나 설정합니다.

Shared

사용자 정의 컨트롤 출력을 여러 페이지에서 공유할 수 있는지 여부를 나타내는 값을 가져옵니다.

SqlDependency

캐시된 사용자 정의 컨트롤이 종속된 하나 이상의 데이터베이스 및 테이블 이름 쌍을 식별하는 구분된 문자열을 가져옵니다.

TypeId

파생 클래스에서 구현된 경우 이 Attribute에 대한 고유 식별자를 가져옵니다.

(다음에서 상속됨 Attribute)
VaryByControls

출력 캐시가 사용자 정의 컨트롤을 변경하는 데 사용하는 사용자 정의 컨트롤 속성의 목록을 가져옵니다.

VaryByCustom

출력 캐시가 사용자 정의 컨트롤을 변경하는 데 사용하는 사용자 지정 문자열의 목록을 가져옵니다.

VaryByParams

출력 캐시가 사용자 정의 컨트롤을 변경하는 데 사용하는 쿼리 문자열이나 폼 POST 매개 변수의 목록을 가져옵니다.

메서드

Equals(Object)

이 인스턴스가 지정된 개체와 같은지를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
GetHashCode()

이 인스턴스의 해시 코드를 반환합니다.

(다음에서 상속됨 Attribute)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IsDefaultAttribute()

파생 클래스에서 재정의된 경우 이 인스턴스 값이 파생 클래스에 대한 기본값인지 여부를 표시합니다.

(다음에서 상속됨 Attribute)
Match(Object)

파생 클래스에서 재정의된 경우 이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

이름 집합을 해당하는 디스패치 식별자 집합에 매핑합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

인터페이스의 형식 정보를 가져오는 데 사용할 수 있는 개체의 형식 정보를 검색합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

개체에서 제공하는 형식 정보 인터페이스의 수를 검색합니다(0 또는 1).

(다음에서 상속됨 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

개체에서 노출하는 메서드와 속성에 대한 액세스를 제공합니다.

(다음에서 상속됨 Attribute)

적용 대상

추가 정보