ASP 101 - Active Server Pages 101 http_cache.aspx
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<SCRIPT Language="VB" Option="Explicit" runat="server">
	Dim strRetrievedHTML As String
	Sub Page_Load(ByVal Src As Object, ByVal E As EventArgs)
		If IsNothing(Cache("http_cache_sample")) Then
			strRetrievedHTML = GetWebPageAsString("")
			Cache.Insert("http_cache_sample", strRetrievedHTML, _
			 Nothing, DateTime.Now.AddMinutes(1), TimeSpan.Zero)
			litCached.Text = "(Not Cached)"
			strRetrievedHTML = Cache("http_cache_sample")
			litCached.Text = "(Cached)"
		End If
	End Sub
	Function GetWebPageAsString(ByVal strURI As String) As String
		Dim objURI As Uri = New Uri(strURI)
		Dim objWebRequest As WebRequest = WebRequest.Create(objURI)
		Dim objWebResponse As WebResponse = objWebRequest.GetResponse()
		Dim objStream As Stream = objWebResponse.GetResponseStream()
		Dim objStreamReader As StreamReader = New StreamReader(objStream)
		Dim strHTML As String = objStreamReader.ReadToEnd
		GetWebPageAsString = strHTML
	End Function
<title>ASP.NET HTTP Request (Cached) Sample from ASP 101</title>
<h2>Retreived HTML <asp:Literal id="litCached" runat="server" />:</h2>
<table border="1" cellpadding="0" cellspacing="0">
The content in the box is retrieved via HTTP and is then cached for up to one minute.
As you refresh the page, pay attention to the timestamp in the returned HTML.
For comparison, it is currently: <%= Now().ToLongTimeString %>
<hr />
Click <a href="">here</a>
to read about and download the source code.