<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% '读取远程文件的函数 Public Function readRemoteFile(RemoteDataUrl) Dim XMLHttp 'On Error Resume Next Set XMLHttp = Server.CreateObject("Microsoft.XMLHTTP") With XMLHttp .Open "Get", RemoteDataUrl, False .Send readRemoteFile = BytesToBstr(.responseBody, "UTF-8") End With Set XMLHttp = Nothing End Function '编码转换 Function BytesToBstr(body,Cset) dim objstream set objstream = Server.CreateObject("adodb.stream") objstream.Type = 1 objstream.Mode =3 objstream.Open objstream.Write body objstream.Position = 0 objstream.Type = 2 objstream.Charset = Cset BytesToBstr = objstream.ReadText objstream.Close set objstream = nothing End Function
Function tobody() Dim dateVal '先试图访问缓存,看有没有,或者过期没有 dateVal = Application("defaultdate") If dateVal = "" Then dateVal = DateAdd("s",1200,Now) If Application("default") <> "" Then If DateDiff("s", Now, dateVal) > 0 Then '如果有,就从缓存读取,对服务器来说,就是从内存读取 tobody = Application("default")&"<!--new cache"&dateVal&"-->" Exit Function End If End If Dim body '如果缓存没有,则从远程读取,并写入缓存,设置缓存时间。 body = readRemoteFile("http://www.aoaob.com/default.asp") tobody = body&"<!--made cache"&Now&"-->" Application.Lock Application("default") = body Application("defaultdate") = DateAdd("s",1200,Now) Application.UnLock End Function Response.Write(tobody()) %>