 |
| 我的知识库 |
 |
|
|
ASP实例:利用缓存提高数据显示效率 |
|
[ 作者: | 文章来源: 网页教学网 | 点击数: 516 | 更新时间: 2007-10-13 17:41:50 ] |
实例演示:先建立一个简单的数据库,写个function读取一下,写入一个dim变量temp中: Spdns@com
ASP代码 Spdns_com
以下为引用的内容: <% 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") Www^Spdns^com rs.Open sql, conn, 1, 3 If Not rs.EOF Then Dim temp temp = " temp = temp & " border=""1"" bordercolor=""silver""" temp = temp & " cellspacing=""2"" cellpadding=""0"">" temp = temp & " | | temp = temp & ">ID操作 | " Www@Spdns@com temp = temp & "数值 | " While Not rs.EOF temp = temp & "" temp = temp & rs("ID") & " | " & rs("szd_f") temp = temp & " | " & rs("szd_t") temp = temp & " | " rs.MoveNext Wend temp = temp & " " 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 Spdns^com datVal = DateAdd("s",Secs,Now) End If temp1 = DateDiff("s", Now, datVal) If temp1 > 0 And retVal <> "" Then DisplayCachedRecords = retVal ' Debugging Code : Response.Write "利用缓存读取数据" Response.Write " ... (" & temp1 & " 秒剩余)" Response.Write "
" Www@Spdns@com 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 "刷新缓存显示 ..." Response.Write "
" End If End Function %>
|
Www_Spdns_com
|
|
|
|