<%
' 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>

'asp' 카테고리의 다른 글

ASP함수 모음  (0) 2011.04.19
초보자를 위한 ASP + MySQL 연동 방법  (0) 2011.04.19
WinHTTP v5.x HTTP Request  (0) 2011.02.16
XML 데이터 파싱하기  (0) 2011.02.16
인증번호생성 함수  (0) 2011.02.16

+ Recent posts