
CacheControl | 361
HttpResponse
Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
sets the cacheability of the of the page to Public. Finally, the Text property of the
Message label control is set to the current time.
Sub Page_Load( )
Dim myCachePol As HttpCachePolicy
myCachePol = Response.Cache
myCachePol.SetExpires(DateTime.Now.AddSeconds(120))
myCachePol.SetCacheability(HttpCacheability.Public)
Message.Text = Now.ToString( )
End Sub
The output of the page should be the current date and time. If refreshed, the
output should not change until two minutes have elapsed.
Notes
The HttpCachePolicy object returned by this property is the preferred method in
ASP.NET for modifying the cache policy for a given page. HttpCachePolicy
provides the functionality provided by the classic ASP CacheControl, Expires, and
ExpiresAbsolute properties. For example, the
HttpCachePolicy class allows you to
explicitly prevent the server from caching the response in question, but still allows
downstream caching of the response.
You can also set the output caching policies for a page through the @ OutputCache
directive and its attributes, although this provides less granular control than
that provided by the methods of the
HttpCachePolicy class. Caching through
the
@ OutputCache directive is discussed in Chapter 3.
CacheControl
Response.CacheControl = String