您现在的位置: 万盛学电脑网 >> 程序编程 >> 网络编程 >> asp编程 >> 正文

asp从缓存读数据实例

作者:佚名    责任编辑:admin    更新时间:2022-06-22

 

从文件读数据,要比直接从数据库快,测试读出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&n