HttpResponse.AddCacheItemDependencies Metoda

Definicja

Sprawia, że ważność buforowanej odpowiedzi zależy od innych elementów w pamięci podręcznej.

Przeciążenia

AddCacheItemDependencies(ArrayList)

Sprawia, że ważność buforowanej odpowiedzi zależy od innych elementów w pamięci podręcznej.

AddCacheItemDependencies(String[])

Sprawia, że ważność buforowanego elementu zależy od innego elementu w pamięci podręcznej.

AddCacheItemDependencies(ArrayList)

Sprawia, że ważność buforowanej odpowiedzi zależy od innych elementów w pamięci podręcznej.

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)

Parametry

cacheKeys
ArrayList

Element ArrayList zawierający klucze elementów, od których zależy bieżąca buforowana odpowiedź.

Przykłady

W poniższym przykładzie pokazano, jak używać strony ASP.NET, która jest zapisywana w pamięci podręcznej. Kod strony tworzy ArrayList obiekt kluczy skojarzonych z elementami przechowywanymi w Cache obiekcie. Następnie kod przekazuje ArrayList parametr jako parametr w wywołaniu AddCacheItemDependencies metody . Powoduje to, że odpowiedź z pamięci podręcznej danych wyjściowych jest nieprawidłowa, jeśli którykolwiek z plików określonych w ArrayList zmianie.

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

Uwagi

Gdy elementy, o których mowa w parametrze cacheKeys , zostaną usunięte z pamięci podręcznej, buforowana odpowiedź bieżącego elementu jest nieprawidłowa.

Zobacz też

Dotyczy

AddCacheItemDependencies(String[])

Sprawia, że ważność buforowanego elementu zależy od innego elementu w pamięci podręcznej.

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

Parametry

cacheKeys
String[]

Tablica kluczy elementów, od których zależy buforowana odpowiedź.

Uwagi

Po usunięciu cacheKeyktóregokolwiek z elementów z pamięci podręcznej buforowana odpowiedź bieżącego elementu jest nieprawidłowa.

Zobacz też

Dotyczy