HttpResponse.AddCacheItemDependencies Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Rende la validità di una risposta memorizzata nella cache dipendente da altri elementi nella cache.
Overload
| Nome | Descrizione |
|---|---|
| AddCacheItemDependencies(ArrayList) |
Rende la validità di una risposta memorizzata nella cache dipendente da altri elementi nella cache. |
| AddCacheItemDependencies(String[]) |
Rende la validità di un elemento memorizzato nella cache dipendente da un altro elemento nella cache. |
AddCacheItemDependencies(ArrayList)
Rende la validità di una risposta memorizzata nella cache dipendente da altri elementi nella 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)
Parametri
- cacheKeys
- ArrayList
Oggetto ArrayList contenente le chiavi degli elementi da cui dipende la risposta memorizzata nella cache corrente.
Esempio
Nell'esempio seguente viene illustrato come usare una pagina di ASP.NET memorizzata nella cache. Il codice per la pagina crea un ArrayList oggetto di chiavi associate agli elementi archiviati nell'oggetto Cache . Successivamente, il codice passa ArrayList come parametro in una chiamata al AddCacheItemDependencies metodo . In questo modo la risposta memorizzata nella cache di output non è valida, se uno dei file specificati nella ArrayList modifica.
<%@ 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>
Commenti
Quando gli elementi a cui si fa riferimento nel cacheKeys parametro vengono rimossi dalla cache, la risposta memorizzata nella cache dell'elemento corrente non è valida.
Vedi anche
Si applica a
AddCacheItemDependencies(String[])
Rende la validità di un elemento memorizzato nella cache dipendente da un altro elemento nella 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())
Parametri
- cacheKeys
- String[]
Matrice di chiavi di elemento da cui dipende la risposta memorizzata nella cache.
Commenti
Quando uno degli cacheKeyoggetti viene rimosso dalla cache, la risposta memorizzata nella cache dell'elemento corrente non è valida.