BasePartialCachingControl.CachePolicy プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > BasePartialCachingControl.CachePolicy プロパティの意味・解説 

BasePartialCachingControl.CachePolicy プロパティ

メモ : このプロパティは、.NET Framework version 2.0 で新しく追加されたものです。

ラップされたユーザー コントロールに関連付けられた ControlCachePolicy オブジェクトを取得します。

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public ReadOnly Property
 CachePolicy As ControlCachePolicy
Dim instance As BasePartialCachingControl
Dim value As ControlCachePolicy

value = instance.CachePolicy
public ControlCachePolicy CachePolicy { get;
 }
public:
property ControlCachePolicy^ CachePolicy {
    ControlCachePolicy^ get ();
}
/** @property */
public ControlCachePolicy get_CachePolicy ()
public function get CachePolicy
 () : ControlCachePolicy

プロパティ値
ラップされたユーザー コントロールのキャッシュ関連のプロパティを格納する ControlCachePolicy。

解説解説
使用例使用例

実行時にプログラムからユーザー コントロールを動的に読み込み、操作する方法を次のコード例に示します。この例は、3 つの部分で構成されます。

この例を正常に実行するには、ユーザー コントロール ファイル (.ascx)、それに対応する分離コード ファイル (.cs または .vb)、およびそのユーザー コントロール (.aspx) をホストする Web フォーム ページが同じディレクトリ内にあることを確認してください。

この例の最初の部分では、PartialCachingAttribute を LogOnControl という名前のユーザー コントロールに適用する方法を示しています。これは、ユーザー コントロールが実行時に PartialCachingControl コントロールによってラップされることを意味します。LogOnControl オブジェクトのキャッシュ設定は、関連付けられた ControlCachePolicy オブジェクト (このオブジェクトをラップする PartialCachingControl への参照を使用してアクセス可能) を通じてプログラムから操作できます。この例では、ページの初期化中にキャッシュ設定がチェックされ、条件が満たされた場合は変更されます。

Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls

<PartialCaching(100)> _
Public Class LogOnControl
   Inherits UserControl

   Public user As TextBox
   Public password As TextBox

End Class 'LogOnControl
using System;
using System.Web.UI;
using System.Web.UI.WebControls;

[PartialCaching(100)]
public class LogOnControl:UserControl
{
    public TextBox user;
    public TextBox password;
}

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

<%@ control inherits = "LogOnControl"
 src = "LogOnControl.vb" %>
<form runat=server>
<table style=font: 10pt verdana;border-width:1;border-style:solid;border-color:black;"
 cellspacing=15>
<tr>
<td><b>Login: </b></td>
<td><ASP:TextBox id="user" runat="server"/></td>
</tr>
<tr>
<td><b>Password: </b></td>
<td><ASP:TextBox id="password" TextMode="Password"
 runat="server"/></td>
</tr>
<tr>
</tr>
</table>
</form>
<%@ control inherits = "LogOnControl" src = "LogOnControl.cs"
 %>
<form runat="server">
<table style=font: 10pt verdana;border-width:1;border-style:solid;border-color:black;"
 cellspacing=15>
<tr>
<td><b>Login: </b></td>
<td><asp:TextBox id="user" runat="server"/></td>
</tr>
<tr>
<td><b>Password: </b></td>
<td><asp:TextBox id="password" TextMode="Password" runat="server"/></td>
</tr>
<tr>
</tr>
</table>
</form>

この例の 3 番目の部分では、Web フォーム ページから LogOnControl ユーザー コントロールを使用する方法を示しています。

<%@ Page Language="VB" Debug = "true"%>
<%@ Reference Control="Logonformvb.ascx" %>
<script language="VB" runat="server">
    ' The following example demonstrates how to load a user control
 dynamically at run time, and
    ' work with the ControlCachePolicy object associated with it.

    ' Loads and displays a UserControl defined in a seperate Logonform.ascx
 file.
    ' You need to have "Logonform.ascx" and "LogOnControl.vb"
 file in 
    ' the same directory as the aspx file.
    Sub Page_Init(ByVal Sender As
 Object, ByVal e As EventArgs)

        ' Obtain a PartialCachingControl object which wraps the 'LogOnControl'
 user control.
        Dim pcc As PartialCachingControl
        pcc = CType(LoadControl("Logonform.vb.ascx"),
 PartialCachingControl)
    
        Dim cacheSettings As ControlCachePolicy
        cacheSettings = pcc.CachePolicy
    
        ' If the control is slated to expire in greater than 60 Seconds
        If (cacheSettings.Duration > TimeSpan.FromSeconds(60))
 Then
        
            ' Make it expire faster. Set a new expiration time to 30
 seconds, and make it
            ' an absolute expiration if it isnt already.        
            cacheSettings.SetExpires(DateTime.Now.Add(TimeSpan.FromSeconds(30)))
            cacheSettings.SetSlidingExpiration(False)
        End If
        Controls.Add(pcc)

    End Sub ' Page_Init
              
</script>
<%@ Page Language="C#" Debug = "true"%>
<%@ Reference Control="Logonformcs.ascx" %>
<script language="C#" runat="server">

// The following example demonstrates how to load a user control dynamically
 at run time, and
// work with the ControlCachePolicy object associated with it.

// Loads and displays a UserControl defined in a seperate Logonform.ascx
 file.
// You need to have "Logonform.ascx" and "LogOnControl.cs"
 file in 
// the same directory as the aspx file. 

void Page_Init(object sender, System.EventArgs e) {
    
    // Obtain a PartialCachingControl object which wraps the 'LogOnControl'
 user control.
    PartialCachingControl pcc = LoadControl("Logonform.cs.ascx") as PartialCachingControl;
        
    
    ControlCachePolicy cacheSettings = pcc.CachePolicy;
    
    // If the control is slated to expire in greater than 60 Seconds
    if (cacheSettings.Duration > TimeSpan.FromSeconds(60) )
 {        
        
        // Make it expire faster. Set a new expiration time to 30 seconds,
 and make it
        // an absolute expiration if it isnt already.        
        cacheSettings.SetExpires(DateTime.Now.Add(TimeSpan.FromSeconds(30)));
        cacheSettings.SetSlidingExpiration(false);
    }                    
    Controls.Add(pcc);
}
</script>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
BasePartialCachingControl クラス
BasePartialCachingControl メンバ
System.Web.UI 名前空間
CachePolicy



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「BasePartialCachingControl.CachePolicy プロパティ」の関連用語

BasePartialCachingControl.CachePolicy プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



BasePartialCachingControl.CachePolicy プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS