HttpResponse.AddCacheItemDependencies Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Torna a validade de uma resposta em cache dependente de outros itens na cache.
Sobrecargas
| Name | Description |
|---|---|
| AddCacheItemDependencies(ArrayList) |
Torna a validade de uma resposta em cache dependente de outros itens na cache. |
| AddCacheItemDependencies(String[]) |
Torna a validade de um item em cache dependente de outro item na cache. |
AddCacheItemDependencies(ArrayList)
Torna a validade de uma resposta em cache dependente de outros itens na 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
O ArrayList que contém as chaves dos itens dos quais depende a resposta em cache atual.
Exemplos
O exemplo seguinte demonstra como usar uma página ASP.NET que está em cache de saída. O código da página cria um ArrayList objeto de chaves associadas a itens armazenados no Cache objeto. De seguida, o código passa o ArrayList como parâmetro numa chamada ao AddCacheItemDependencies método. Isto torna a resposta em cache de saída inválida, se algum dos ficheiros especificados na ArrayList alteração.
<%@ 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>
Observações
Quando os itens referidos no cacheKeys parâmetro são removidos da cache, a resposta em cache do item atual deixa de ser válida.
Ver também
Aplica-se a
AddCacheItemDependencies(String[])
Torna a validade de um item em cache dependente de outro item na 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[]
Um array de chaves de itens do qual a resposta em cache depende.
Observações
Quando qualquer um dos cacheKeys é removido da cache, a resposta em cache do item atual torna-se inválida.