ASP實(shí)例:利用緩存提高數(shù)據(jù)顯示效率_ASP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:Windows 2003 安裝設(shè)置iis安裝篇 2003默認(rèn)安裝不帶IIS的,要安裝,請點(diǎn)擊開始->管理工具->配置您的服務(wù)器向?qū)? 然后一步步的下一步。到了列表選擇項(xiàng)目的時(shí)候。 從列表中選擇 應(yīng)用服務(wù)器(IIS,ASP.NET)
實(shí)例演示:先建立一個(gè)簡單的數(shù)據(jù)庫,寫個(gè)function讀取一下,寫入一個(gè)dim變量temp中:
ASP代碼
| 以下為引用的內(nèi)容: <% Function DisplayRecords() Dim sql, conn, rs sql = "SELECT id, [szd_f], [szd_t] FROM admin" Set conn = Server.CreateObject("ADODB.Connection") conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="&Server.MapPath("db.mdb") Set rs = Server.CreateObject("ADODB.Recordset") rs.Open sql, conn, 1, 3 If Not rs.EOF Then Dim temp temp = "<table width=""90%"" align=""center""" temp = temp & " border=""1"" bordercolor=""silver""" temp = temp & " cellspacing=""2"" cellpadding=""0"">" temp = temp & "<tr bgcolor=""#CCDDEE""><td width=""5%""" temp = temp & ">ID</td><td>操作</td>" temp = temp & "<td>數(shù)值</td></tr>" While Not rs.EOF temp = temp & "<tr><td bgcolor=""#CCDDEE"">" temp = temp & rs("ID") & "</td><td>" & rs("szd_f") temp = temp & "</td><td>" & rs("szd_t") temp = temp & "</td></tr>" rs.MoveNext Wend temp = temp & "</table>" DisplayRecords = temp Else DisplayRecords = "Data Not Available." End If rs.Close conn.Close Set rs = Nothing Set conn = Nothing End Function '寫入緩存 Function DisplayCachedRecords(Secs) Dim retVal, datVal, temp1 retVal = Application("cache_demo") datVal = Application("cache_demo_date") If datVal = "" Then datVal = DateAdd("s",Secs,Now) End If temp1 = DateDiff("s", Now, datVal) If temp1 > 0 And retVal <> "" Then DisplayCachedRecords = retVal ' Debugging Code : Response.Write "<b><font color=""green"">利用緩存讀取數(shù)據(jù)" Response.Write " ... (" & temp1 & " 秒剩余)</font></b>" Response.Write "<br><br>" Else Dim temp2 ' Change DisplayRecords() to the function whose ' value you want to cache temp2 = DisplayRecords() Application.Lock Application("cache_demo") = temp2 Application("cache_demo_date") = DateAdd("s",Secs,Now) Application.UnLock DisplayCachedRecords = temp2 ' Debugging Code : Response.Write "<b><font color=""red"">刷新緩存顯示 ..." Response.Write "</font></b><br><br>" End If End Function %> <!-- Response.Write DisplayRecords() --> <html> <head> <title>利用緩存從數(shù)據(jù)庫---讀取數(shù)據(jù)</title> <style> body, p, td { font-family:Sans-Serif; font-size:8pt; } td { padding-left: 5; } </style> </head> <body> <% Dim t1, t2 t1 = Timer Response.Write DisplayCachedRecords(20) t2 = Timer %> <p align="center"> 停留時(shí)間: <%= Left((CDbl((t2 - t1) * 1000.0)), 5) %> ms </p> </body> </html> |
分享:ASP基礎(chǔ)教程之ASP AdRotator 組件的使用ASP AdRotator 組件 每當(dāng)用戶進(jìn)入網(wǎng)站或刷新頁面時(shí),ASP AdRotator組件就會創(chuàng)建一個(gè)AdRotator對象來顯示一幅不同的圖片。 語法: 以下為引用的內(nèi)容
相關(guān)ASP教程:
- asp FSO 讀寫文件本文件實(shí)現(xiàn)代碼
- asp中isNull、isEmpty和空字符串的區(qū)別
- asp獲取用戶真實(shí)IP地址的方法
- asp連接sqlserver數(shù)據(jù)庫實(shí)現(xiàn)代碼
- asp中正則表達(dá)式過濾html代碼函數(shù)
- asp中g(shù)et post提交表單區(qū)別
- 網(wǎng)頁模板:ASP內(nèi)建對象Request
- xmlhttp的open方法使用詳解
- ASP的常用的自定義函數(shù)大全
- asp中用for循環(huán)的一個(gè)小技巧
- eWebEditor v3.8 列目錄
- ASP無組件分頁實(shí)現(xiàn)思路及代碼
- 相關(guān)鏈接:
- 教程說明:
ASP教程-ASP實(shí)例:利用緩存提高數(shù)據(jù)顯示效率
。