ASP 101 - Active Server Pages 101 - Web06
The Place ASP Developers Go!

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash





ASP Source Code:
<%
' This sample examines the caching side of things.  For more
' details on the HTTP request aspect of the code, see our two
' previous HTTP samples:
'     http://www.asp101.com/samples/winhttp5.asp (WinHttp version)
'     http://www.asp101.com/samples/http.asp (older MSXML version)
Dim strCached  ' string to hold text telling user if page was cached
' Check to see if the expiration date of the cached data has passed.
If Application("http_cache_sample_expires") < Now() Then
	Dim objWinHttp ' HTTP request object
	Set objWinHttp = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
	objWinHttp.Open "GET", "http://www.asp101.com/samples/httpsamp.asp"
	objWinHttp.Send
	' If we get a valid response then we save the data to an
	' application variable and set another to indicate how long
	' the data should be kept.
	If objWinHttp.Status = "200" Then
		Application.Lock
		' Save the response to an application level variable
		Application("http_cache_sample_content") = objWinHttp.ResponseText
		' Set the expiration time.  As an example I'm adding 1 minute to
		' the current time, but you can do whatever works best for you.
		Application("http_cache_sample_expires") = DateAdd("n", 1, Now())
		Application.UnLock
	End If
	' Trash our HTTP object now that I'm finished with it.
	Set objWinHttp = Nothing
	strCached = "Not Cached"
Else
	strCached = "Cached"
End If
%>
<h2>Retreived HTML (<%= strCached %>):</h2>
<table border="1" cellpadding="0" cellspacing="0">
<tr><td>
<pre>
<%= Server.HtmlEncode(Application("http_cache_sample_content")) %>
</pre>
</td></tr>
</table>
<p>
The cached data will expire at: <%= Server.HtmlEncode(Application("http_cache_sample_expires")) %>
</p>
<p>
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() %>
</p>

Back the the Sample Output

Back to the Sample Index


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers