
374
|
Chapter 17: The HttpResponse Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
Notes
The AddFileDependencies method is useful when you want to output cache a
page, but the page depends on the value of several files on the web server (which
can be accessed by a file path from the web server). Rather than caching the page
with a very short duration to avoid stale data, you can use AddFileDependencies
to automatically invalidate the output cache when the dependencies change.
AddFileDependency
Response.AddFileDependency(ByVal filename As String)
Adds a file to the list of files upon which the output cache of the current request
depends. If the named by the filename argument is modified, the output cache is
invalidated.
Parameter
filename
A String containing the path and filename to add.
Example
The example below shows how you can use the AddFileDependency method to
set a file as a dependency for the output cache of the current response. If the file is
modified, the output cache is invalidated.
<%@ Page Language="vb" %>
<%@ OutputCache Duration="300" VaryByParam="None" %>
<html>
<head>
<title>Adding a file dependency in ASP.NET</title>
<script runat="server">
Sub Page_Load( )
Response.AddFileDependency(Server.MapPath("dep.txt"))
Message.Text = DateTime.Now.ToString( )
End Sub
</script>
</head>
<body>
<asp:label id="Message" runat="server"/> ...