2005-10-07

提高数据显示效率--缓存探幽

来源: 本站收集整理 作者:佚名 评论 0 条
 

'该函数是写入缓存
Function DisplayCachedRecords(Secs)
Dim retVal, datVal, temp1
'Secs是每次要刷新数据的时间, retVal是数据,datVal是剩余时间
retVal = Application("cache_demo") '取得appliction的值
datVal = Application("cache_demo_date") '取得appliction的值
'判定datVal 的值,也就是要计算时间过去了没
If datVal = "" Then
'假如是空,datVal值为当前时间按秒加上secs定义的时间
datVal = DateAdd("s",Secs,Now)
End If
'temp1是判定当前时间和datVal的秒差
temp1 = DateDiff("s", Now, datVal)
'假如retVal已经是上面函数的返回值且时间大于0
If temp1 > 0 And retVal <> "" Then
'本函数返回记录数
DisplayCachedRecords = retVal
Response.Write "<b><font color=""green"">利用缓存读取数据"
Response.Write " ... (" & temp1 & " 秒剩余)</font></b>"
Response.Write "<br><br>"
Else
'retVal 是空的话,就赋予DisplayRecords的值给变量temp2
Dim temp2
temp2 = DisplayRecords()
'保存到Application.------------------>重点
Application.Lock
Application("cache_demo") = temp2
Application("cache_demo_date") = DateAdd("s",Secs,Now)
Application.UnLock
DisplayCachedRecords = temp2
' 这里随便写上了记录的缓存的过去时间,相对总秒数倒差 :
Response.Write "<b><font color=""red"">刷新缓存显示 ..."
Response.Write "</font></b><br><br>"
End If
End Function
%>

说明完毕.

以下为完整无注释代码

<%
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>数值</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)
共3页: 上一页 [1] 2 [3] 下一页

(本文仅表明作者个人观点,不代表本站及其管理员立场.) 推荐 收藏 投稿 打印 返回 关闭
上一篇:C#中同一DataTable中合并相同条件的行数据  
下一篇:Taglib 原理和实现之什么是Taglib
    评论加载中…
 推荐文章
     

网站首页  -  网站地图 -   站长论坛  -  网站投稿  -    -  网站管理
Copyright © 2008 芜湖站长站 All Rights Reserved 皖ICP备07500611号