PartialCachingAttribute クラス

定義

Web フォーム ユーザー コントロール (.ascx files) が、出力をキャッシュするかどうか、およびその方法を示すために使用するメタデータ属性を定義します。 このクラスは継承できません。

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 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

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

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

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

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

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

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

コンストラクター

PartialCachingAttribute(Int32)

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

PartialCachingAttribute(Int32, String, String, String)

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

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

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

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

キャッシュの存続期間、GET および POST の値、コントロール名、キャッシュを変更するために使用するカスタム出力キャッシュ要件、データベースの依存関係、およびユーザー コントロール出力を複数のページで共有できるようにするかどうかを指定して、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)

適用対象

こちらもご覧ください