HttpResponse.AddCacheItemDependencies 方法

定义

使缓存响应的有效性依赖于缓存中的其他项。

重载

AddCacheItemDependencies(ArrayList)

使缓存响应的有效性依赖于缓存中的其他项。

AddCacheItemDependencies(String[])

使缓存项的有效性依赖于缓存中的另一项。

AddCacheItemDependencies(ArrayList)

使缓存响应的有效性依赖于缓存中的其他项。

public:
 void AddCacheItemDependencies(System::Collections::ArrayList ^ cacheKeys);
public void AddCacheItemDependencies (System.Collections.ArrayList cacheKeys);
member this.AddCacheItemDependencies : System.Collections.ArrayList -> unit
Public Sub AddCacheItemDependencies (cacheKeys As ArrayList)

参数

cacheKeys
ArrayList

ArrayList,其中包含当前缓存的响应所依赖的项的键。

示例

以下示例演示如何使用缓存输出的 ASP.NET 页。 页面的代码创建一个 ArrayList 键对象,这些键与存储在 对象中的 Cache 项相关联。 接下来,代码在调用 AddCacheItemDependencies 方法时将 作为 参数传递ArrayList。 如果更改中指定的 ArrayList 任何文件,这会使输出缓存响应无效。

<%@ Page Language="C#" %>
<%@ outputcache duration="30" varybyparam="none" %>
<%@ Import namespace="Samples.AspNet.CS" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="Server">
    private void Page_Load(object sender, System.EventArgs e)
    {

        // Create an array list that
        // contains the keys for two
        // items stored in the Cache object.
        ArrayList deps = new ArrayList();
        deps.Add("bookData");
        deps.Add("authorData");
    
        // Make the page invalid if either of the
        // cached items change or expire.        
        Response.AddCacheItemDependencies(deps);

        // Populate the DataGrids.
        dgAuthors.DataSource = DataHelper.GetAuthorData();
        dgAuthors.DataBind();

        dgBooks.DataSource = DataHelper.GetBookData();
        dgBooks.DataBind();

        lblOutputCacheMsg.Text = DateTime.Now.ToString();

    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Cache Item Dependencies</title> 
</head>
<body>
    <form id="Form1" method="post" runat="server">
        <table>
            <tbody>
                <tr>
                    <th style="WIDTH: 118px">
                        Authors</th>
                    <td>
                        <asp:DataGrid id="dgAuthors" runat="server"></asp:DataGrid>
                    </td>
                </tr>
                <tr>
                    <th style="WIDTH: 118px">
                        Books</th>
                    <td>
                        <asp:DataGrid id="dgBooks" runat="server"></asp:DataGrid>
                    </td>
                </tr>
                <tr>
                    <td style="WIDTH: 118px">
                        The page was generated at:</td>
                    <td>
                        <asp:Label id="lblOutputCacheMsg" runat="server"></asp:Label>
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
</body>
</html>
<%@ Page Language="vb" %>
<%@ outputcache duration="30" varybyparam="none" %>
<%@ Import namespace="Samples.AspNet.VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    Private Sub Page_Load(sender As Object, e As System.EventArgs)
       ' Create an array list that
       ' contains the keys for two
       ' items stored in the Cache object.
       Dim deps As New ArrayList()
       deps.Add("bookData")
       deps.Add("authorData")
    
       ' Make the page invalid if either of the
       ' cached items change or expire.
       Response.AddCacheItemDependencies(deps)
    
       ' Populate the DataGrids.
       dgAuthors.DataSource = DataHelper.GetAuthorData()
       dgAuthors.DataBind()
    
       dgBooks.DataSource = DataHelper.GetBookData()
       dgBooks.DataBind()
    
       lblOutputCacheMsg.Text = DateTime.Now.ToString()
    End Sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Cache Item Dependencies</title> 
</head>
<body>
    <form id="Form1" method="post" runat="server">
        <table>
            <tbody>
                <tr>
                    <th style="WIDTH: 118px">
                        Authors</th>
                    <td>
                        <asp:DataGrid id="dgAuthors" runat="server"></asp:DataGrid>
                    </td>
                </tr>
                <tr>
                    <th style="WIDTH: 118px">
                        Books</th>
                    <td>
                        <asp:DataGrid id="dgBooks" runat="server"></asp:DataGrid>
                    </td>
                </tr>
                <tr>
                    <td style="WIDTH: 118px">
                        The page was generated at:</td>
                    <td>
                        <asp:Label id="lblOutputCacheMsg" runat="server"></asp:Label>
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
</body>
</html>

注解

从缓存中删除 参数中 cacheKeys 引用的项时,当前项的缓存响应无效。

另请参阅

适用于

AddCacheItemDependencies(String[])

使缓存项的有效性依赖于缓存中的另一项。

public:
 void AddCacheItemDependencies(cli::array <System::String ^> ^ cacheKeys);
public void AddCacheItemDependencies (string[] cacheKeys);
member this.AddCacheItemDependencies : string[] -> unit
Public Sub AddCacheItemDependencies (cacheKeys As String())

参数

cacheKeys
String[]

一个项键的数组,缓存响应依赖于这些项键。

注解

当从缓存中删除任何 cacheKeys 时,当前项的缓存响应无效。

另请参阅

适用于