HttpResponse.AddCacheItemDependencies Metodo

Definizione

Rende la validità di una risposta memorizzata nella cache dipendente da altri elementi della cache.

Overload

AddCacheItemDependencies(ArrayList)

Rende la validità di una risposta memorizzata nella cache dipendente da altri elementi della cache.

AddCacheItemDependencies(String[])

Rende la validità di un elemento memorizzato nella cache dipendente da un altro elemento della cache.

AddCacheItemDependencies(ArrayList)

Rende la validità di una risposta memorizzata nella cache dipendente da altri elementi della 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

L'oggetto ArrayList contenente le chiavi degli elementi da cui dipende la risposta corrente memorizzata nella cache.

Esempio

Nell'esempio seguente viene illustrato come usare una pagina di ASP.NET memorizzata nella cache. Il codice della pagina crea un ArrayList oggetto di chiavi associate agli elementi archiviati nell'oggetto Cache . Successivamente, il codice passa come ArrayList parametro in una chiamata al AddCacheItemDependencies metodo. Ciò rende 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 della 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 delle chiavi dell'elemento da cui dipende la risposta memorizzata nella cache.

Commenti

Quando uno degli cacheKeyelementi viene rimosso dalla cache, la risposta memorizzata nella cache dell'elemento corrente non è valida.

Vedi anche

Si applica a