Name
AddCacheItemDependency
Synopsis
Response.AddCacheItemDependency(ByVal cacheKey As String)
Adds a cache item key to the list of cache keys upon which the output cache of the current response depends. If the cache item identified by the key is modified, the output cache of the current response will be invalidated and a fresh response will be generated.
Parameters
-
cacheKey
A String containing the cache item key to add.
Example
The example shows how you can use the AddCacheItemDependency method to set a cache key as a dependency for the output cache of the current response. If the cache item represented by this key is modified, the output cache is invalidated and the page is refreshed by using Response.Redirect.
<%@ Page Language="vb" %> <%@ OutputCache Duration="300" VaryByParam="None" %> <html> <head> <title>Adding a cache dependency in ASP.NET</title> <script runat="server"> Sub Page_Load( ) Response.AddCacheItemDependency("Key1") Message.Text = DateTime.Now.ToString( ) End Sub Sub Button1_Click(sender As Object, e As EventArgs) Cache("Key1") = "foo" & DateTime.Now.ToString( ) Response.Redirect("AddCacheItemDependency.aspx") End Sub </script> </head> <body> <form runat="server"> <asp:label id="Message" runat="server"/> <asp:button id="Button1" text="Change Key 1" onClick="Button1_ Click" runat="server"/> </form> </body> </html>
Notes
The AddCacheItemDependency method provides the same functionality as the AddCacheItemDependencies method, but for a single cache item rather than multiple ...
Get ASP.NET in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.