ASP提高数据显示效率:缓存探幽(2)

2008-02-23 09:38:41来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折


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
Response.Write "<b><font color=""green"">利用缓存读取数据"
Response.Write " ... (" & temp1 & " 秒剩余)</font></b>"
Response.Write "<br><br>"
Else
Dim temp2
temp2 = DisplayRecords()
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
%>

调用方法:

<%=DisplayCachedRecords(20)%>

写在后面的话:如果你感觉你的服务器内存不够大的话,不要大量使用缓存.

下载: cache.rar

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:纯ASP代码之公历转农历实现(含属相)--例子代码

下一篇:ASP小偷偷取地址并生成html