Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
AddCacheItemDependencies Method (ArrayList)
Collapse the table of content
Expand the table of content

HttpResponse.AddCacheItemDependencies Method (ArrayList)

Makes the validity of a cached response dependent on other items in the cache.

Namespace:  System.Web
Assembly:  System.Web (in System.Web.dll)

public void AddCacheItemDependencies(
	ArrayList cacheKeys


Type: System.Collections.ArrayList

The ArrayList that contains the keys of the items that the current cached response is dependent upon.

When the items referred to in the cacheKeys parameter are removed from the cache, the cached response of the current item is not valid.

The following example demonstrates how to use an ASP.NET page that is output cached. The code for the page creates an ArrayList object of keys that are associated with items that are stored in the Cache object. Next, the code passes the ArrayList as the parameter in a call to the AddCacheItemDependencies method. 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"
<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();

        // Make the page invalid if either of the
        // cached items change or expire.        

        // Populate the DataGrids.
        dgAuthors.DataSource = DataHelper.GetAuthorData();

        dgBooks.DataSource = DataHelper.GetBookData();

        lblOutputCacheMsg.Text = DateTime.Now.ToString();



<html xmlns="http://www.w3.org/1999/xhtml" >
    <title>Cache Item Dependencies</title> 
    <form id="Form1" method="post" runat="server">
                    <th style="WIDTH: 118px">
                        <asp:DataGrid id="dgAuthors" runat="server"></asp:DataGrid>
                    <th style="WIDTH: 118px">
                        <asp:DataGrid id="dgBooks" runat="server"></asp:DataGrid>
                    <td style="WIDTH: 118px">
                        The page was generated at:</td>
                        <asp:Label id="lblOutputCacheMsg" runat="server"></asp:Label>

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
© 2015 Microsoft