ASP實(shí)例:利用緩存提高數(shù)據(jù)顯示效率_ASP教程
教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!
推薦:Windows 2003 安裝設(shè)置iis安裝篇 2003默認(rèn)安裝不帶IIS的,要安裝,請(qǐng)點(diǎn)擊開始->管理工具->配置您的服務(wù)器向?qū)? 然后一步步的下一步。到了列表選擇項(xiàng)目的時(shí)候。 從列表中選擇 應(yīng)用服務(wù)器(IIS,ASP.NET)
實(shí)例演示:先建立一個(gè)簡(jiǎn)單的數(shù)據(jù)庫(kù),寫個(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ù)庫(kù)---讀取數(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)站或刷新頁(yè)面時(shí),ASP AdRotator組件就會(huì)創(chuàng)建一個(gè)AdRotator對(duì)象來(lái)顯示一幅不同的圖片。 語(yǔ)法: 以下為引用的內(nèi)容
相關(guān)ASP教程:
- asp FSO 讀寫文件本文件實(shí)現(xiàn)代碼
- asp中isNull、isEmpty和空字符串的區(qū)別
- asp獲取用戶真實(shí)IP地址的方法
- asp連接sqlserver數(shù)據(jù)庫(kù)實(shí)現(xiàn)代碼
- asp中正則表達(dá)式過(guò)濾html代碼函數(shù)
- asp中g(shù)et post提交表單區(qū)別
- 網(wǎng)頁(yè)模板:ASP內(nèi)建對(duì)象Request
- xmlhttp的open方法使用詳解
- ASP的常用的自定義函數(shù)大全
- asp中用for循環(huán)的一個(gè)小技巧
- eWebEditor v3.8 列目錄
- ASP無(wú)組件分頁(yè)實(shí)現(xiàn)思路及代碼
ASP教程Rss訂閱編程教程搜索
ASP教程推薦
- ASP把長(zhǎng)的數(shù)字用逗號(hào)隔開顯示
- ASP Request對(duì)象的使用
- asp有效防止網(wǎng)站留言板出現(xiàn)垃圾留言/評(píng)論實(shí)現(xiàn)思路
- 在ASP查詢條件中包含單引號(hào)時(shí)的解決方法
- 小技巧:解決ASP腳本運(yùn)行超時(shí)的方法
- ASP中DateAdd函數(shù)中日期相加或相減使用方法
- server.mappath方法詳解
- ASP實(shí)例:Asp 防止網(wǎng)頁(yè)頻繁刷新一法
- ASP 3.0高級(jí)編程(四十四)
- 學(xué)ASp動(dòng)態(tài)網(wǎng)頁(yè)必備:常用的38個(gè)函數(shù)
- 相關(guān)鏈接:
- 教程說(shuō)明:
ASP教程-ASP實(shí)例:利用緩存提高數(shù)據(jù)顯示效率
。