PartialCachingAttribute クラス

定義

Web フォーム のユーザー コントロール (.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の使用方法を示します。 この例には、次の 3 つの部分があります。

  • ctlMine基底クラスから継承され、UserControl属性が適用される部分クラス (PartialCachingAttribute)。

  • ctlMine部分クラスで使用されるユーザー コントロール。

  • ユーザー コントロールをホストする Web フォーム ページ。

この例の最初の部分では、 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

この例の 2 番目の部分は、前の例でユーザー コントロールのキャッシュを示すために使用されるユーザー コントロールを示しています。

<!-- 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" />

この例の 3 番目の部分では、ユーザー コントロールをホストする Web フォーム ページを示します。

<!-- 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の使用は、出力キャッシュを有効にできるいくつかの方法の 1 つです。 次の一覧では、出力キャッシュを有効にするために使用できるメソッドについて説明します。

  • 宣言型のシナリオで出力キャッシュを有効にするには、 @ OutputCache ディレクティブを使用します。

  • PartialCachingAttributeを使用して、分離コード ファイル内のユーザー コントロールのキャッシュを有効にします。

  • ControlCachePolicy クラスを使用して、BasePartialCachingControl インスタンスを操作するプログラムによるシナリオでキャッシュ設定をプログラムで指定します。

ユーザー コントロールに @ OutputCache ディレクティブが含まれている場合、または PartialCachingAttribute が適用されている場合、ASP.NET パーサーはユーザー コントロールをラップする PartialCachingControl クラスのインスタンスを生成します。

ASP.NET キャッシュの詳細については、「Caching」を参照してください。 属性の使用の詳細については、「 属性」を参照してください。

コンストラクター

名前 説明
PartialCachingAttribute(Int32, String, String, String, Boolean)

キャッシュ期間、GETPOSTの値、コントロール名、キャッシュの変更に使用されるカスタム出力キャッシュ要件、およびユーザー コントロールの出力を複数のページと共有できるかどうかを指定して、PartialCachingAttribute クラスの新しいインスタンスを初期化します。

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

キャッシュ期間、GETPOST値、コントロール名、キャッシュの変更に使用されるカスタム出力キャッシュ要件、データベースの依存関係、およびユーザー コントロールの出力を複数のページで共有できるかどうかを指定して、PartialCachingAttribute クラスの新しいインスタンスを初期化します。

PartialCachingAttribute(Int32, String, String, String)

キャッシュ期間、GET 値と POST 値、コントロール名、キャッシュの変更に使用されるカスタム出力キャッシュ要件を指定して、 PartialCachingAttribute クラスの新しいインスタンスを初期化します。

PartialCachingAttribute(Int32)

キャッシュするユーザー コントロールに割り当てられた指定した期間を使用して、 PartialCachingAttribute クラスの新しいインスタンスを初期化します。

プロパティ

名前 説明
Duration

キャッシュされた項目が出力キャッシュに残る時間 (秒単位) を取得します。

ProviderName

関連付けられたコントロールの出力キャッシュ データを格納するために使用されるプロバイダーの名前を取得または設定します。

Shared

ユーザー コントロールの出力を複数のページと共有できるかどうかを示す値を取得します。

SqlDependency

キャッシュされたユーザー コントロールが依存している 1 つ以上のデータベースとテーブル名のペアを識別する区切り文字列を取得します。

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)

適用対象

こちらもご覧ください