asp從緩存讀數(shù)據(jù)實(shí)例_ASP教程
教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!
推薦:asp防止網(wǎng)頁(yè)刷新代碼減輕服務(wù)器負(fù)擔(dān),asp防止網(wǎng)頁(yè)刷新代碼 SubPreventRefresh() DimRefreshTime,isRefresh RefreshTime=10防止刷新時(shí)間,單位(秒) isRefresh=1是否使用防刷新功能,0=否,1=是 IfisRefresh=1Then If(NotIsEmpty(Session(RefreshTime)))AndRefreshTime0Then IfDateDiff(s,Se
-
從文件讀數(shù)據(jù),要比直接從數(shù)據(jù)庫(kù)快,測(cè)試讀出6000條新聞,讀數(shù)據(jù)庫(kù)用了23579毫秒,讀文件只用了123毫秒,下例為使用文件緩存的代碼
使用方法,在需要使用文件緩存的頁(yè)面加入下列代碼,
<!--#include file="FileCatch.asp" -->
<%
Set MyCatch=new CatchFile
MyCatch.Overdue=10 ’修改過(guò)期時(shí)間設(shè)置為10分鐘
if MyCatch.CatchNow(Rev) then
response.write MyCatch.CatchData
response.end
end if
set MyCatch=nothing
%>
FileCatch.asp
復(fù)制內(nèi)容到剪貼板代碼:
<%
’ 本文件用于簽入原始文件,實(shí)現(xiàn)對(duì)頁(yè)面的文件Catch
’ 1、如果文件請(qǐng)求為POST方式,則取消此功能
’ 2、文件的請(qǐng)求不能包含系統(tǒng)的識(shí)別關(guān)鍵字
Class CatchFile
Public Overdue,Mark,CFolder,CFile ’定義系統(tǒng)參數(shù)
Private ScriptName,ScriptPath,ServerHost ’定義服務(wù)器/頁(yè)面參數(shù)變量
Public CatchData ’輸出的數(shù)據(jù)
Private Sub Class_Initialize ’初始化函數(shù)
’獲得服務(wù)器及腳本數(shù)據(jù)
ScriptName=Request.Servervariables("Script_Name") ’識(shí)別出當(dāng)前腳本的虛擬地址
ScriptPath=GetScriptPath(false) ’識(shí)別出腳本的完整GET地址
ServerHost=Request.Servervariables("Server_Name") ’識(shí)別出當(dāng)前服務(wù)器的地址
’初始化系統(tǒng)參數(shù)
Overdue=30 ’默認(rèn)30分鐘過(guò)期
Mark="NoCatch" ’無(wú)Catch請(qǐng)求參數(shù)為 NoCatch
CFolder=GetCFolder ’定義默認(rèn)的Catch文件保存目錄
CFile=Server.URLEncode(ScriptPath)&".txt" ’將腳本路徑轉(zhuǎn)化為文件路徑
CatchData=""
end Sub
Private Function GetCFolder
dim FSO,CFolder
Set FSO=CreateObject("Scripting.FileSystemObject") ’設(shè)置FSO對(duì)象
CFolder=Server.MapPath("/")&"/FileCatch/"
if not FSO.FolderExists(CFolder) then
fso.CreateFolder(CFolder)
end if
if Month(Now())<10 then
CFolder=CFolder&"/0"&Month(Now())
else
CFolder=CFolder&Month(Now())
end if
if Day(Now())<10 then
CFolder=CFolder&"0"&Day(Now())-
else
CFolder=CFolder&Day(Now())
end if
CFolder=CFolder&"/"
if not FSO.FolderExists(CFolder) then
fso.CreateFolder(CFolder)
end if
GetCFolder=CFolder
set fso=nothing
End Function
Private Function bytes2BSTR(vIn) ’轉(zhuǎn)換編碼的函數(shù)
dim StrReturn,ThisCharCode,i,NextCharCode
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
Public Function CatchNow(Rev) ’用戶指定開(kāi)始處理Catch操作
if UCase(request.Servervariables("Request_Method"))="POST" then
’當(dāng)是POST方法,不可使用文件Catch
Rev="使用POST方法請(qǐng)求頁(yè)面,不可以使用文件Catch功能"
CatchNow=false
else
if request.Querystring(Mark)<>"" then
’如果指定參數(shù)不為空,表示請(qǐng)求不可以使用Catch-
Rev="請(qǐng)求拒絕使用Catch功能"
CatchNow=false
else
CatchNow=GetCatchData(Rev)
end if
end if
End Function
Private Function GetCatchData(Rev) ’讀取Catch數(shù)據(jù)
Dim FSO,IsBuildCatch
Set FSO=CreateObject("Scripting.FileSystemObject") ’設(shè)置FSO對(duì)象,訪問(wèn)CatchFile
If FSO.FileExists(CFolder&CFile) Then
Dim File,LastCatch
Set File=FSO.GetFile(CFolder&CFile) ’定義CatchFile文件對(duì)象
LastCatch=CDate(File.DateLastModified)
if DateDiff("n",LastCatch,Now())>Overdue then
’如果超過(guò)了Catch時(shí)間
IsBuildCatch=true
else
IsBuildCatch=false
end if
Set File=Nothing
else
IsBuildCatch=true
End if
If IsBuildCatch then
GetCatchData=http://www.code-123.com/html/BuildCatch(Rev) ’如果需要?jiǎng)?chuàng)建Catch,則創(chuàng)建Catch文件,同時(shí)設(shè)置Catch的數(shù)據(jù)
else
GetCatchData=http://www.code-123.com/html/ReadCatch(Rev) ’如果不需要?jiǎng)?chuàng)建Catch,則直接讀取Catch數(shù)據(jù)
End if
Set FSO=nothing-
End Function
Private Function GetScriptPath(IsGet) ’創(chuàng)建一個(gè)包含所有請(qǐng)求數(shù)據(jù)的地址
dim Key,Fir
GetScriptPath=ScriptName
Fir=true
for Each key in Request.QueryString
If Fir then
GetScriptPath=GetScriptPath&"?"
Fir=false
else
GetScriptPath=GetScriptPath&"&"
end if
GetScriptPath=GetScriptPath&Server.URLEncode(Key)&"="&Server.URLEncode(Request.QueryString(Key))
Next
if IsGet then
If Fir then
GetScriptPath=GetScriptPath&"?"
Fir=false
else
GetScriptPath=GetScriptPath&"&"
end if
GetScriptPath=GetScriptPath&Server.URLEncode(Mark)&"=yes"
end if
End Function
’創(chuàng)建Catch文件
Private Function BuildCatch(Rev)
Dim HTTP,Url,OutCome
Set HTTP=CreateObject("Microsoft.XMLHTTP")
’ On Error Resume Next
’ response.write ServerHost&GetScriptPath(true)
HTTP.Open "get","http://"&ServerHost&GetScriptPath(true),False
HTTP.Send
if Err.number=0 then
CatchData=http://www.code-123.com/html/bytes2BSTR(HTTP.responseBody)-
BuildCatch=True
else
Rev="創(chuàng)建發(fā)生錯(cuò)誤:"&Err.Description
BuildCatch=False
Err.clear
end if
Call WriteCatch
set HTTP=nothing
End Function
Private Function ReadCatch(Rev)
ReadCatch=IReadCatch(CFolder&CFile,CatchData,Rev)
End Function
Private Sub WriteCatch
Dim FSO,TSO
Set FSO=CreateObject("Scripting.FileSystemObject") ’設(shè)置FSO對(duì)象,訪問(wèn)CatchFile
set TSO=FSO.CreateTextFile(CFolder&CFile,true)
TSO.Write(CatchData)
Set TSO=Nothing
Set FSO=Nothing
End Sub
End Class
Function IReadCatch(File,Data,Rev)
Dim FSO,TSO
Set FSO=CreateObject("Scripting.FileSystemObject") ’設(shè)置FSO對(duì)象,訪問(wèn)CatchFile
’ on error resume next
set TSO=FSO.OpenTextFile(File,1,false)
Data=http://www.code-123.com/html/TSO.ReadAll
if Err.number<>0 then
Rev="讀取發(fā)生錯(cuò)誤:"&Err.Description
ReadCatch=False
Err.clear
else
IReadCatch=True
end if
Set TSO=Nothing
Set FSO=Nothing
End Function
%>
-
BuildCatch=True
-
End Function
-
Rev="請(qǐng)求拒絕使用Catch功能"
-
else
分享:asp調(diào)用c#編制的com組件實(shí)例1新建類庫(kù)MyTestDLL 2右擊項(xiàng)目MyTestDLL-》屬性-》生成-》勾選為COM互操作注冊(cè) 3打開(kāi)AssemblyInfo.cs文件修改[assembly:ComVisible(true)] 4打開(kāi)VisualSutdio2008的命令提示行工具輸入guidgen.exe選擇DEFINE_GUID單擊NewGUID 5代碼 1、每個(gè)類名對(duì)應(yīng)一個(gè)接口名,接口名
相關(guān)ASP教程:
- asp FSO 讀寫文件本文件實(shí)現(xiàn)代碼
- asp中isNull、isEmpty和空字符串的區(qū)別
- asp獲取用戶真實(shí)IP地址的方法
- asp連接sqlserver數(shù)據(jù)庫(kù)實(shí)現(xiàn)代碼
- asp中正則表達(dá)式過(guò)濾html代碼函數(shù)
- asp中g(shù)et post提交表單區(qū)別
- 網(wǎng)頁(yè)模板:ASP內(nèi)建對(duì)象Request
- xmlhttp的open方法使用詳解
- ASP的常用的自定義函數(shù)大全
- asp中用for循環(huán)的一個(gè)小技巧
- eWebEditor v3.8 列目錄
- ASP無(wú)組件分頁(yè)實(shí)現(xiàn)思路及代碼
ASP教程Rss訂閱編程教程搜索
ASP教程推薦
- ASP優(yōu)化 用數(shù)據(jù)綁定實(shí)現(xiàn)高效率動(dòng)態(tài)網(wǎng)頁(yè)
- 解讀處理多關(guān)鍵詞查詢實(shí)例代碼
- 如何用Asp取得數(shù)據(jù)庫(kù)中所有表名和字段名
- ASP中set與dim的區(qū)別(自己的理解)
- 解析ASP與存儲(chǔ)過(guò)程
- ASP判斷數(shù)據(jù)庫(kù)值是否為空的通用函數(shù)
- 通用獲取文章上下各三篇文章的代碼
- 如何在ASP中遍歷和操作Application對(duì)象的集合
- 教大家如何利用ASP打造網(wǎng)站論壇DIY(2)
- ASP教程:解決ASP腳本運(yùn)行超時(shí)的方法
- 相關(guān)鏈接:
- 教程說(shuō)明:
ASP教程-asp從緩存讀數(shù)據(jù)實(shí)例
。