佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > asp偽靜態(tài)情況下實(shí)現(xiàn)的utf-8文件緩存實(shí)現(xiàn)代碼

asp偽靜態(tài)情況下實(shí)現(xiàn)的utf-8文件緩存實(shí)現(xiàn)代碼

熱門(mén)標(biāo)簽:銀行業(yè)務(wù) 團(tuán)購(gòu)網(wǎng)站 服務(wù)器配置 電子圍欄 科大訊飛語(yǔ)音識(shí)別系統(tǒng) Linux服務(wù)器 Mysql連接數(shù)設(shè)置 阿里云
復(fù)制代碼 代碼如下:

%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
% Response.CodePage=65001%>
% Response.Charset="UTF-8" %>
%
'該程序通過(guò)使用ASP的FSO功能,減少數(shù)據(jù)庫(kù)的讀取。經(jīng)測(cè)試,可以減少90%的服務(wù)器負(fù)荷。頁(yè)面訪問(wèn)速度基本與靜態(tài)頁(yè)面相當(dāng)。
'使用方法:將該文件放在網(wǎng)站里,然后在需要引用的文件的“第一行”用include引用即可。
'=======================參數(shù)區(qū)=============================
DirName="cachenew\" '靜態(tài)文件保存的目錄,結(jié)尾應(yīng)帶"\"。無(wú)須手動(dòng)建立,程序會(huì)自動(dòng)建立。
TimeDelay=30 '更新的時(shí)間間隔,單位為分鐘,如1440分鐘為1天。生成的靜態(tài)文件在該間隔之后會(huì)被刪除。
'======================主程序區(qū)============================
foxrax=Request("foxrax")
if foxrax="" then
FileName=GetStr()".txt"
FileName=DirNameFileName
if tesfold(DirName)=false then'如果不存在文件夾則創(chuàng)建
createfold(Server.MapPath(".")"\"DirName)
end if
if ReportFileStatus(Server.MapPath(".")"\"FileName)=true then'如果存在生成的靜態(tài)文件,則直接讀取文件
Set FSO=CreateObject("Scripting.FileSystemObject")
Dim Files,LatCatch
Set Files=FSO.GetFile(Server.MapPath(FileName)) '定義CatchFile文件對(duì)象
LastCatch=CDate(Files.DateLastModified)
If DateDiff("n",LastCatch,Now())>TimeDelay Then'超過(guò)
List=getHTTPPage(GetUrl())
WriteFile(FileName)
Else
List=ReadFile(FileName)
End If
Set FSO = nothing
Response.Write(List)
Response.End()
else
List=getHTTPPage(GetUrl())
WriteFile(FileName)
end if

end if

'========================函數(shù)區(qū)============================
'獲取當(dāng)前頁(yè)面url
Function GetStr()
'On Error Resume Next
Dim strTemps
strTemps = strTemps Request.ServerVariables("HTTP_X_REWRITE_URL")
GetStr = Server.URLEncode(strTemps)
End Function
'獲取緩存頁(yè)面url
Function GetUrl()
On Error Resume Next
Dim strTemp
If LCase(Request.ServerVariables("HTTPS")) = "off" Then
strTemp = "http://"
Else
strTemp = "https://"
End If
strTemp = strTemp Request.ServerVariables("SERVER_NAME")
If Request.ServerVariables("SERVER_PORT") > 80 Then
strTemp = strTemp ":" Request.ServerVariables("SERVER_PORT")
end if
strTemp = strTemp Request.ServerVariables("URL")
If Trim(Request.QueryString) > "" Then
strTemp = strTemp "?" Trim(Request.QueryString) "foxrax=foxrax"
else
strTemp = strTemp "?" "foxrax=foxrax"
end if
GetUrl = strTemp
End Function

'抓取頁(yè)面
Function getHTTPPage(url)
Set Mail1 = Server.CreateObject("CDO.Message")
Mail1.CreateMHTMLBody URL,31
AA=Mail1.HTMLBody
Set Mail1 = Nothing
getHTTPPage=AA
'Set Retrieval = Server.CreateObject("Microsoft.Xmlhttp")
'Retrieval.Open "GET",url,false,"",""
'Retrieval.Send
'getHTTPPage = Retrieval.ResponseBody
'Set Retrieval = Nothing
End Function
Sub WriteFile(filePath)
dim stm
set stm=Server.CreateObject("adodb.stream")
stm.Type=2 'adTypeText,文本數(shù)據(jù)
stm.Mode=3 'adModeReadWrite,讀取寫(xiě)入,此參數(shù)用2則報(bào)錯(cuò)
stm.Charset="utf-8"
stm.Open
stm.WriteText list
stm.SaveToFile Server.MapPath(filePath),2 'adSaveCreateOverWrite,文件存在則覆蓋
stm.Flush
stm.Close
set stm=nothing
End Sub

Function ReadFile(filePath)
dim stm
set stm=Server.CreateObject("adodb.stream")
stm.Type=1 'adTypeBinary,按二進(jìn)制數(shù)據(jù)讀入
stm.Mode=3 'adModeReadWrite ,這里只能用3用其他會(huì)出錯(cuò)
stm.Open
stm.LoadFromFile Server.MapPath(filePath)
stm.Position=0 '把指針移回起點(diǎn)
stm.Type=2 '文本數(shù)據(jù)
stm.Charset="utf-8"
ReadFile = stm.ReadText
stm.Close
set stm=nothing
End Function
'檢測(cè)文件是否存在
Function ReportFileStatus(FileName)
set fso = server.createobject("scripting.filesystemobject")
if fso.fileexists(FileName) = true then
ReportFileStatus=true
else
ReportFileStatus=false
end if
set fso=nothing
end function
'檢測(cè)目錄是否存在
function tesfold(foname)
set fs=createobject("scripting.filesystemobject")
filepathjm=server.mappath(foname)
if fs.folderexists(filepathjm) then
tesfold=True
else
tesfold= False
end if
set fs=nothing
end function
'建立目錄
sub createfold(foname)
set fs=createobject("scripting.filesystemobject")
fs.createfolder(foname)
set fs=nothing
end sub
'刪除文件
function del_file(path) 'path,文件路徑包含文件名
set objfso = server.createobject("scripting.FileSystemObject")
'path=Server.MapPath(path)
if objfso.FileExists(path) then '若存在則刪除
objfso.DeleteFile(path) '刪除文件
else
'response.write "script language='Javascript'>alert('文件不存在')/script>"
end if
set objfso = nothing
end function
%>

標(biāo)簽:江蘇 棗莊 衡水 衢州 萍鄉(xiāng) 蚌埠 大理 廣元

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp偽靜態(tài)情況下實(shí)現(xiàn)的utf-8文件緩存實(shí)現(xiàn)代碼》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    甘谷县| 如东县| 鄂托克旗| 顺昌县| 咸宁市| 巧家县| 临泽县| 塔城市| 长武县| 海晏县| 石柱| 尉犁县| 方山县| 固原市| 田林县| 明水县| 忻州市| 天柱县| 郎溪县| 吴旗县| 东源县| 乌审旗| 崇左市| 阳高县| 泸溪县| 武功县| 民勤县| 洪洞县| 寻乌县| 全椒县| 泸溪县| 独山县| 凤山县| 汨罗市| 涟源市| 中方县| 石城县| 中超| 田林县| 任丘市| 时尚|