<%
’’下面的function用來從動網(wǎng)論壇數(shù)據(jù)庫中提出數(shù)據(jù)更新緩存 很簡單的 提出最新發(fā)表的十個帖子
function refreshrecords()
Dim sql, conn, rs
sql = "select top 10 * FROM Dv_Topic order by DateAndTime desc"
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="&server.mappath("dv.mdb")
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql,conn, 1, 1
If Not rs.EOF Then
Dim temp
temp="
refreshrecords = temp
Else
refreshrecords = "數(shù)據(jù)調(diào)用失敗."
End If
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
End Function
’’下面的function則是用來更新緩存的
function displayrecords(secs)
if Application("cache")="" or isempty(Application("cache")) then ’’’’ 程序第一次運行時候更新緩存
’’’’application("cache")用來保存我們需要緩存在內(nèi)存中的內(nèi)容
’’’’application("cache_time")用來保留緩存上次更新的時間
’’’’我們只在兩種情況下是需要調(diào)用refresh函數(shù)來訪問數(shù)據(jù)庫來更新緩存
’’’’第一種就是服務器重啟 或者其他意外導致application存儲的值丟失
Application.Lock
Application("cache_date")=now()
’’更新緩存時間
Application("cache") = refreshrecords()
’’更新緩存內(nèi)容
’’codeby niceidea 簽名
Application.UnLock
end if
if DateDiff("s", Application("cache_date"),Now)> secs then ’’比較上次更新時間與當前時間的差值
’’’’另外一種需要更新緩存的情況就是緩存到期 所謂緩存就是保留一定時間的數(shù)據(jù) 定期更新恐怕是最常見的
Application.Lock
Application("cache_date")=now()
Application("cache") = refreshrecords()
Application.UnLock
end if
Response.Write Application("cache")
End Function
%>
最后 調(diào)用的方法是
<%displayrecords(300)%>
300表示5分鐘更新一次 60×5=300!
’’下面的function用來從動網(wǎng)論壇數(shù)據(jù)庫中提出數(shù)據(jù)更新緩存 很簡單的 提出最新發(fā)表的十個帖子
function refreshrecords()
Dim sql, conn, rs
sql = "select top 10 * FROM Dv_Topic order by DateAndTime desc"
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="&server.mappath("dv.mdb")
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql,conn, 1, 1
If Not rs.EOF Then
Dim temp
temp="
- "
- boardID="&rs("Boardid")&"&ID="&rs
("topicid")&"&page=1"">"&rs("Title")&"("&rs("PostUserName")
&") "
for i=1 to 10
temp = temp&"
’’這個地方各有所好了,顯然和一個用table,td,tr,tbody來寫前臺的人合作,是一件很痛苦的事情.
rs.MoveNext
i=i+1
next
temp = temp & "
refreshrecords = temp
Else
refreshrecords = "數(shù)據(jù)調(diào)用失敗."
End If
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
End Function
’’下面的function則是用來更新緩存的
function displayrecords(secs)
if Application("cache")="" or isempty(Application("cache")) then ’’’’ 程序第一次運行時候更新緩存
’’’’application("cache")用來保存我們需要緩存在內(nèi)存中的內(nèi)容
’’’’application("cache_time")用來保留緩存上次更新的時間
’’’’我們只在兩種情況下是需要調(diào)用refresh函數(shù)來訪問數(shù)據(jù)庫來更新緩存
’’’’第一種就是服務器重啟 或者其他意外導致application存儲的值丟失
Application.Lock
Application("cache_date")=now()
’’更新緩存時間
Application("cache") = refreshrecords()
’’更新緩存內(nèi)容
’’codeby niceidea 簽名
Application.UnLock
end if
if DateDiff("s", Application("cache_date"),Now)> secs then ’’比較上次更新時間與當前時間的差值
’’’’另外一種需要更新緩存的情況就是緩存到期 所謂緩存就是保留一定時間的數(shù)據(jù) 定期更新恐怕是最常見的
Application.Lock
Application("cache_date")=now()
Application("cache") = refreshrecords()
Application.UnLock
end if
Response.Write Application("cache")
End Function
%>
最后 調(diào)用的方法是
<%displayrecords(300)%>
300表示5分鐘更新一次 60×5=300!