從文件讀數(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文件保存目錄