asp自帶的內(nèi)存緩存 application
更新時間:2009年12月21日 23:17:19 作者:
asp強大的application 是 php 中所沒有的。昨天朋友抱怨他的人才網(wǎng)站讀取速度慢,于是我?guī)退補sp中讀庫比較費時的部分用application做了緩存。
函數(shù)getcache,會自動建立需要的緩存。
Function getcache(funsname,isreset,isarr,timeinfo)
‘funsname — 需要緩存的內(nèi)容,這里要輸入一個function名
‘isreset –是否更新[值:0(根據(jù)時間或判斷緩存為空時自動更新)、1(主動更新)]
‘ isarr —- 所緩存的內(nèi)容是否為一個數(shù)據(jù)[0為字符串,1為數(shù)組]
‘ timeinfo —- 緩存更新時間,單位為秒,當(dāng)值為0時,則只在緩存為空時,才更新
dim domain = “cnzhaopin.com.cn”
Dim temp_getconfig
Dim re_getcache : re_getcache = False
Dim temp_isarray_type : temp_isarray_type = False
Dim Appfunsname : Appfunsname = Replace(Replace(Replace(funsname,”(”,”"),”)”,”"),”,”,”.”)
If isarr = 1 Then temp_isarray_type = True
If isreset = 1 Then re_getcache = True
If isreset = 2 Then
execute(”temp_getconfig=”&funsname)
getcache = temp_getconfig
Exit Function
End If
If Application(domain&”_”&Appfunsname&”_time”) = “” And timeinfo<>0 Then re_getcache = True
If Not re_getcache Then
If temp_isarray_type Then
If Not IsArray(Application(domain&”_”&Appfunsname)) Then re_getcache = True
Else
If Application(domain&”_”&Appfunsname) = “” Then re_getcache = True
End If
End If
If Not re_getcache And timeinfo<>0 Then
If Int(DateDiff(”s”,Application(domain&”_”&Appfunsname&”_time”),now()))>timeinfo Then re_getcache = True
End If
If re_getcache Then
execute(”temp_getconfig=”&funsname)
Application.Lock
Application(domain&”_”&Appfunsname) = temp_getconfig
Application(domain&”_”&Appfunsname&”_time”) = Now()
Application.UnLock
Else
temp_getconfig=Application(domain&”_”&Appfunsname)
End If
getcache = temp_getconfig
End Function
使用時:
Function output3
output3=”"
set newrs=conn.execute(”select TOP 60 companyname,comid,vipdata,ishot from company where isok=1 and vipqx>60 and vipqx<300 and vip=1 and comid in (select comid from jobs where zt<>1) order by newid()”)
do while not newrs.eof
output3=output3 & “……….”
newrs.movenext
loop
newrs.close
set newrs=nothing
End function
response.write getcache(”output3″,0,0,3600)
復(fù)制代碼 代碼如下:
Function getcache(funsname,isreset,isarr,timeinfo)
‘funsname — 需要緩存的內(nèi)容,這里要輸入一個function名
‘isreset –是否更新[值:0(根據(jù)時間或判斷緩存為空時自動更新)、1(主動更新)]
‘ isarr —- 所緩存的內(nèi)容是否為一個數(shù)據(jù)[0為字符串,1為數(shù)組]
‘ timeinfo —- 緩存更新時間,單位為秒,當(dāng)值為0時,則只在緩存為空時,才更新
dim domain = “cnzhaopin.com.cn”
Dim temp_getconfig
Dim re_getcache : re_getcache = False
Dim temp_isarray_type : temp_isarray_type = False
Dim Appfunsname : Appfunsname = Replace(Replace(Replace(funsname,”(”,”"),”)”,”"),”,”,”.”)
If isarr = 1 Then temp_isarray_type = True
If isreset = 1 Then re_getcache = True
If isreset = 2 Then
execute(”temp_getconfig=”&funsname)
getcache = temp_getconfig
Exit Function
End If
If Application(domain&”_”&Appfunsname&”_time”) = “” And timeinfo<>0 Then re_getcache = True
If Not re_getcache Then
If temp_isarray_type Then
If Not IsArray(Application(domain&”_”&Appfunsname)) Then re_getcache = True
Else
If Application(domain&”_”&Appfunsname) = “” Then re_getcache = True
End If
End If
If Not re_getcache And timeinfo<>0 Then
If Int(DateDiff(”s”,Application(domain&”_”&Appfunsname&”_time”),now()))>timeinfo Then re_getcache = True
End If
If re_getcache Then
execute(”temp_getconfig=”&funsname)
Application.Lock
Application(domain&”_”&Appfunsname) = temp_getconfig
Application(domain&”_”&Appfunsname&”_time”) = Now()
Application.UnLock
Else
temp_getconfig=Application(domain&”_”&Appfunsname)
End If
getcache = temp_getconfig
End Function
使用時:
復(fù)制代碼 代碼如下:
Function output3
output3=”"
set newrs=conn.execute(”select TOP 60 companyname,comid,vipdata,ishot from company where isok=1 and vipqx>60 and vipqx<300 and vip=1 and comid in (select comid from jobs where zt<>1) order by newid()”)
do while not newrs.eof
output3=output3 & “……….”
newrs.movenext
loop
newrs.close
set newrs=nothing
End function
response.write getcache(”output3″,0,0,3600)
您可能感興趣的文章:
- ASP編程入門進階(九):內(nèi)置對象Application
- javascript asp教程第十一課--Application 對象
- asp清空application的方法
- ASP javascript Application對象的Contents和StaticObjects做Cache的一些經(jīng)驗
- ASP.NET內(nèi)置對象之Application對象
- asp.net Reporting Service在Web Application中的應(yīng)用
- php和asp利用Shell.Application來執(zhí)行程序的代碼
- ASP.NET中Application和Cache的區(qū)別分析
- asp.net錯誤處理Application_Error事件示例
- ASP.NET 使用application與session對象寫的簡單聊天室程序
- ASP基礎(chǔ)入門第八篇(ASP內(nèi)建對象Application和Session)
相關(guān)文章
asp 關(guān)鍵詞字符串分割如何實現(xiàn)方法
asp 關(guān)鍵詞字符串分割如何實現(xiàn)方法...2007-11-11asp實現(xiàn)獲取MSSQL數(shù)據(jù)庫表指定條件行數(shù)的函數(shù)
這篇文章主要介紹了asp實現(xiàn)獲取MSSQL數(shù)據(jù)庫表指定條件行數(shù)的函數(shù)的的相關(guān)資料,需要的朋友可以參考下2015-03-03ASP Access實現(xiàn)網(wǎng)站計數(shù)器(訪問量)
學(xué)習(xí)asp的朋友需要了解下2008-11-11