<%
function readdb()
Dim objconn,objrs
set objconn=server.createobject("ADODB.Connection")
objconn.connectionstring="Provider=Microsoft.Jet.OLEDB.4.0;" &_
"Data Source=" & server.mappath("db.mdb")
objconn.open
set objrs=server.createobject("ADODB.Recordset")
objrs.open "admin",objconn,1,2,2
temp=""
temp=temp&"<div align='center'><center>"
temp=temp&"<table border='1' cellpadding='0' cellspacing='0' width='300' bordercolor='#0066CC' bordercolorlight='#0066CC' bordercolordark='#0066CC'>"
temp=temp & "<tr><td bgcolor='#0030CC' align='center' height='26'><font color='#FFFFFF'>ID</font></td>"
temp=temp & "<td bgcolor='#0030CC' align='center' height='26'><font color='#FFFFFF'>szd_f</font></td>"
temp=temp & "<td bgcolor='#0030CC' align='center' height='26'><font color='#FFFFFF'>szd_t</font></td></tr>"
Do while not objrs.Eof
temp=temp & "<tr><td align='center' height='24'>" & objrs("id") & "</td>"
temp=temp & "<td align='center' height='24'>" & objrs("szd_f") & "</td>"
temp=temp & "<td align='center' height='24'>" & objrs("szd_t") & "</td></tr>"
objrs.movenext
Loop
temp=temp & "</table></center></div>"
readdb=temp
End function
function readcache(secs)
Dim temp1,temp2,cachedata,cachedate
cachedata=application("cachedata")
cachedate=application("cachedate")
if cachedate=Empty then
cachedate=dateadd("s",secs,now)
End if
temp1=datediff("s",now,cachedate)
if temp1>0 and cachedata<>Empty then
temp2=application("cachedata")
Response.write "<p align='center'><font color='#009933'><b>讀取快取資料,離重新整理時間還有" & temp1 & "秒</b></font></p>"
else
application.lock
application("cachedata")=readdb()
application("cachedate")=dateadd("s",secs,now)
application.unlock
temp2=application("cachedata")
Response.write "<p align='center'><font color='#FF0000'><b>讀取資料庫資料</b></font></p>"
End if
readcache=temp2
End function
%>
<html>
asp緩衝技術
<head><title>cachetest</title><style>
<!--
td{font-size:9pt;}
-->
</style>
</head>
<body>
<% Dim starttime,endtime
starttime=timer
Response.write readcache(20)
endtime=timer
Response.write "<p align='center'>頁面已耗用時間為:" & round((endtime-starttime)*1000.0,2) & "ms</p>"
%>
</body>
</html>