HttpResponse.AddCacheItemDependency メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HttpResponse.AddCacheItemDependency メソッドの意味・解説 

HttpResponse.AddCacheItemDependency メソッド

キャッシュ内の他のアイテム依存するキャッシュされた応答有効にます。

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

Public Sub AddCacheItemDependency ( _
    cacheKey As String _
)
Dim instance As HttpResponse
Dim cacheKey As String

instance.AddCacheItemDependency(cacheKey)
public void AddCacheItemDependency (
    string cacheKey
)
public:
void AddCacheItemDependency (
    String^ cacheKey
)
public void AddCacheItemDependency (
    String cacheKey
)
public function AddCacheItemDependency (
    cacheKey : String
)

パラメータ

cacheKey

キャッシュされた応答依存するアイテムキー

解説解説
使用例使用例

次のコード例は、出力キャッシュされた ASP.NET ユーザー コントロールです。このコントロールコードは、AddCacheItemDependency メソッド呼び出しCache オブジェクト格納されているアイテムキーパラメータとして渡します該当するアイテムキャッシュない場合出力キャッシュ格納されていたコントロール応答無効になります。つまり、後続要求では、そのコントロール応答新しバージョン出力キャッシュ追加されます。

次に、bookData キー関連付けられているアイテムCache オブジェクト格納されているかどうか確認しその結果に応じて 1 行または 2 行のテキスト表示します続いて、DataGrid コントロールの DataSource プロパティである dgBooks を、カスタム DataHelper クラス共有 GetBookData メソッド呼び出して設定し、DataGrid を DataBind メソッド使用して設定します

<%@ Control Language="vb" %>
<%@ Outputcache duration="10" varybyparam="none"
 shared="True" %>
<%@ Import Namespace="Samples.AspNet.VB"
 %>
<%@ Import Namespace="System.Data"
 %>
<script runat="server">

    Private Sub Page_Load(sender As
 Object, e As System.EventArgs)
    
        ' Make user control invalid if the 
        ' cache item changes or expires.
        Response.AddCacheItemDependency("bookData")


        ' Create a DataView object.
        Dim source As DataView = Cache("bookData")
    
        ' Check if the view is stored in the cache
        ' and generate the right label text
        ' dependent upon what is returned.
        If source Is Nothing
 Then

           source = DataHelper.GetBookData()
           lblCacheMsg.Text = "Data generated explicitly."
        Else
           lblCacheMsg.Text = "Data retrieved from application
 cache."
        End If
    
        dgBooks.DataSource = source
        dgBooks.DataBind()
    
        lblOutputMessage.Text = DateTime.Now.ToString()
    End Sub

</script>

    <table>
        <tbody>
            <tr>
                <th>
                    Books</th>
                <td>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:DataGrid id="dgBooks"
 runat="server"></asp:DataGrid>
                </td>
                <td>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label id="lblCacheMsg"
 runat="server"></asp:Label>
                </td>
                <td>
                </td>
            </tr>
            <tr>
                <td>
                    The control was created at: 
                </td>
                <td>
                    <asp:Label id="lblOutputMessage"
 runat="server"></asp:Label>
                </td>
            </tr>
        </tbody>
    </table>
     
    <%@ Control Language="c#" %>
    <%@ Outputcache duration="10" varybyparam="none" shared="True"
 %>
    <%@ Import Namespace = "Samples.AspNet.CS" %>
    <%@ Import Namespace = "System.Data" %>

<script runat="server">

    private void Page_Load(object sender, System.EventArgs
 e)
    {
    
        // Make user control invalid if the
        // cache item changes or expires.
        Response.AddCacheItemDependency("bookData");

        // Create a DataView object.
        DataView source = (DataView)Cache["bookData"];
    
        // Check if the view is stored in the cache
        // and generate the right label text
        // dependent upon what is returned.
        if (source == null)
        {
            source = DataHelper.GetBookData();
            lblCacheMsg.Text = "Data generated explicitly.";
        }
        else
        {
            lblCacheMsg.Text = "Data retrieved from application cache.";
        }
    
        dgBooks.DataSource = source;
        dgBooks.DataBind();
    
        lblOutputMessage.Text = DateTime.Now.ToString();
    }

</script>
    <table>
        <tbody>
            <tr>
                <th>
                    Books</th>
                <td>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:DataGrid id="dgBooks" runat="server"></asp:DataGrid>
                </td>
                <td>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label id="lblCacheMsg" runat="server"></asp:Label>
                </td>
                <td>
                </td>
            </tr>
            <tr>
                <td>
                    The control was created at: 
                </td>
                <td>
                    <asp:Label id="lblOutputMessage" runat="server"></asp:Label>
                </td>
            </tr>
        </tbody>
    </table>
    <%@ Control Language="VJ#" %>
    <%@ Outputcache duration="10" varybyparam="none" shared="True"
 %>
    <%@ Import Namespace = "Samples.AspNet.JSL" %>
    <%@ Import Namespace = "System.Data" %>

<script runat="server">

    private void Page_Load(Object sender, System.EventArgs
 e)
    {
        // Make user control invalid if the
        // cache item changes or expires.
        get_Response().AddCacheItemDependency("bookData");

        // Create a DataView object.
        DataView source = (System.Data.DataView)(get_Cache()
            .get_Item("bookData"));

        // Check if the view is stored in the cache
        // and generate the right label text
        // dependent upon what is returned.
        
        if (source == null) {
            source = DataHelper.GetBookData();
            lblCacheMsg.set_Text("Data generated explicitly.");
        }
        else {
            lblCacheMsg.set_Text("Data retrieved from application cache.");
        }

        dgBooks.set_DataSource(source);
        dgBooks.DataBind();

        lblOutputMessage.set_Text(DateTime.get_Now().ToString());
    } //Page_Load

</script>
    <table>
        <tbody>
            <tr>
                <th>
                    Books</th>
                <td>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:DataGrid id="dgBooks" runat="server"></asp:DataGrid>
                </td>
                <td>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label id="lblCacheMsg" runat="server"></asp:Label>
                </td>
                <td>
                </td>
            </tr>
            <tr>
                <td>
                    The control was created at: 
                </td>
                <td>
                    <asp:Label id="lblOutputMessage" runat="server"></asp:Label>
                </td>
            </tr>
        </tbody>
    </table>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

HttpResponse.AddCacheItemDependency メソッドのお隣キーワード
検索ランキング

   

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



HttpResponse.AddCacheItemDependency メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS