国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

asp從緩存讀數據實例_ASP教程

2024-05-04 11:04:40
字體:
來源:轉載
供稿:網友

推薦:asp防止網頁刷新代碼
減輕服務器負擔,asp防止網頁刷新代碼 SubPreventRefresh() DimRefreshTime,isRefresh RefreshTime=10防止刷新時間,單位(秒) isRefresh=1是否使用防刷新功能,0=否,1=是 IfisRefresh=1Then If(NotIsEmpty(Session(RefreshTime)))AndRefreshTime0Then IfDateDiff(s,Se

 

從文件讀數據,要比直接從數據庫快,測試讀出6000條新聞,讀數據庫用了23579毫秒,讀文件只用了123毫秒,下例為使用文件緩存的代碼  
使用方法,在需要使用文件緩存的頁面加入下列代碼, 
<!--#include file="FileCatch.asp" --> 
<% 
Set MyCatch=new CatchFile 
MyCatch.Overdue=10     ’修改過期時間設置為10分鐘 
if MyCatch.CatchNow(Rev) then 
        response.write MyCatch.CatchData 
        response.end 
end if 
set MyCatch=nothing 

%> 
FileCatch.asp 
復制內容到剪貼板代碼: 
<% 
’ 本文件用于簽入原始文件,實現對頁面的文件Catch 
’ 1、如果文件請求為POST方式,則取消此功能 
’ 2、文件的請求不能包含系統的識別關鍵字 
Class CatchFile 
        Public Overdue,Mark,CFolder,CFile ’定義系統參數 
        Private ScriptName,ScriptPath,ServerHost ’定義服務器/頁面參數變量 
        Public CatchData        ’輸出的數據 
        Private Sub Class_Initialize        ’初始化函數 
                ’獲得服務器及腳本數據 
                ScriptName=Request.Servervariables("Script_Name") ’識別出當前腳本的虛擬地址 
                ScriptPath=GetScriptPath(false)        ’識別出腳本的完整GET地址 
                ServerHost=Request.Servervariables("Server_Name") ’識別出當前服務器的地址
                ’初始化系統參數 
                Overdue=30        ’默認30分鐘過期 
                Mark="NoCatch"        ’無Catch請求參數為 NoCatch 
                CFolder=GetCFolder        ’定義默認的Catch文件保存目錄 
                CFile=Server.URLEncode(ScriptPath)&".txt"        ’將腳本路徑轉化為文件路徑 
                CatchData="" 
        end Sub 
        Private Function GetCFolder 
                dim FSO,CFolder 
                Set FSO=CreateObject("Scripting.FileSystemObject")        ’設置FSO對象 
                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)        ’轉換編碼的函數 
                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)        ’用戶指定開始處理Catch操作 
                if UCase(request.Servervariables("Request_Method"))="POST" then 
                ’當是POST方法,不可使用文件Catch 
                        Rev="使用POST方法請求頁面,不可以使用文件Catch功能" 
                        CatchNow=false 
                else 
                        if request.Querystring(Mark)<>"" then 
                        ’如果指定參數不為空,表示請求不可以使用Catch
 Rev="請求拒絕使用Catch功能" 
                                CatchNow=false 
                        else 
                                CatchNow=GetCatchData(Rev) 
                        end if 
                end if 
        End Function 
        Private Function GetCatchData(Rev)        ’讀取Catch數據 
                Dim FSO,IsBuildCatch 
                Set FSO=CreateObject("Scripting.FileSystemObject")        ’設置FSO對象,訪問CatchFile 
                If FSO.FileExists(CFolder&CFile) Then 
                        Dim File,LastCatch 
                        Set File=FSO.GetFile(CFolder&CFile)        ’定義CatchFile文件對象
                        LastCatch=CDate(File.DateLastModified) 
                        if DateDiff("n",LastCatch,Now())>Overdue then 
                        ’如果超過了Catch時間 
                                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)        ’如果需要創建Catch,則創建Catch文件,同時設置Catch的數據 
                else 
                        GetCatchData=http://www.code-123.com/html/ReadCatch(Rev)        ’如果不需要創建Catch,則直接讀取Catch數據 
                End if 
                Set FSO=nothing
 End Function 
        Private Function GetScriptPath(IsGet)        ’創建一個包含所有請求數據的地址 
                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 
        ’創建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="創建發生錯誤:"&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")        ’設置FSO對象,訪問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")        ’設置FSO對象,訪問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="讀取發生錯誤:"&Err.Description 
                ReadCatch=False 
                Err.clear 
        else 
                IReadCatch=True 
        end if 
        Set TSO=Nothing 
        Set FSO=Nothing 
End Function 
%>

分享:asp調用c#編制的com組件實例
1新建類庫MyTestDLL 2右擊項目MyTestDLL-》屬性-》生成-》勾選為COM互操作注冊 3打開AssemblyInfo.cs文件修改[assembly:ComVisible(true)] 4打開VisualSutdio2008的命令提示行工具輸入guidgen.exe選擇DEFINE_GUID單擊NewGUID 5代碼 1、每個類名對應一個接口名,接口名

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 九龙坡区| 松潘县| 阿克陶县| 包头市| 鹰潭市| 邹平县| 临夏县| 远安县| 安庆市| 大关县| 邳州市| 壤塘县| 辽宁省| 玛纳斯县| 搜索| 隆子县| 元朗区| 衡阳县| 年辖:市辖区| 湘潭县| 阿克苏市| 屯留县| 赫章县| 巩义市| 乐亭县| 庆云县| 无为县| 乐山市| 阿拉善盟| 勐海县| 康马县| 民勤县| 武安市| 石嘴山市| 文水县| 廊坊市| 溆浦县| 辉南县| 灵台县| 边坝县| 锡林郭勒盟|