HttpResponse.AddCacheItemDependencies Método

Definição

Torna a validade de uma resposta em cache dependente de outros itens no cache.Makes the validity of a cached response dependent on other items in the cache.

Sobrecargas

AddCacheItemDependencies(ArrayList)

Torna a validade de uma resposta em cache dependente de outros itens no cache.Makes the validity of a cached response dependent on other items in the cache.

AddCacheItemDependencies(String[])

Torna a validade de um item em cache dependente de outro item no cache.Makes the validity of a cached item dependent on another item in the cache.

AddCacheItemDependencies(ArrayList)

Torna a validade de uma resposta em cache dependente de outros itens no cache.Makes the validity of a cached response dependent on other items in the cache.

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)

Parâmetros

cacheKeys
ArrayList

A ArrayList que contém as chaves dos itens dos quais a resposta atualmente armazenada em cache é dependente.The ArrayList that contains the keys of the items that the current cached response is dependent upon.

Exemplos

O exemplo a seguir demonstra como usar uma página ASP.NET que é de saída armazenada em cache.The following example demonstrates how to use an ASP.NET page that is output cached. O código para a página cria um ArrayList objeto de chaves que são associadas a itens que são armazenados no Cache objeto.The code for the page creates an ArrayList object of keys that are associated with items that are stored in the Cache object. Em seguida, o código passa o ArrayList como o parâmetro em uma chamada para o AddCacheItemDependencies método.Next, the code passes the ArrayList as the parameter in a call to the AddCacheItemDependencies method. Isso torna a resposta armazenada em cache de saída inválida, se qualquer um dos arquivos especificados na ArrayList alteração.This makes the output cached response not valid, if any of the files specified in the ArrayList change.

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

Comentários

Quando os itens referenciados no cacheKeys parâmetro são removidos do cache, a resposta armazenada em cache do item atual não é válida.When the items referred to in the cacheKeys parameter are removed from the cache, the cached response of the current item is not valid.

Confira também

Aplica-se a

AddCacheItemDependencies(String[])

Torna a validade de um item em cache dependente de outro item no cache.Makes the validity of a cached item dependent on another item in the cache.

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

Parâmetros

cacheKeys
String[]

Uma matriz de chaves de itens dos quais a resposta armazenada em cache é dependente.An array of item keys that the cached response is dependent upon.

Comentários

Quando qualquer um dos cacheKey s é removido do cache, a resposta armazenada em cache do item atual é inválida.When any of the cacheKeys are removed from the cache, the cached response of the current item is invalid.

Confira também

Aplica-se a