欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

利用 cache 做對(duì)比靜態(tài)頁(yè)的網(wǎng)頁(yè)技術(shù)

 更新時(shí)間:2007年10月27日 12:04:48   作者:  
一直想寫一套生成靜態(tài)頁(yè)面的文章系統(tǒng) 但面對(duì)生成靜態(tài)后的一些復(fù)雜數(shù)據(jù)庫(kù)交互問(wèn)題。又望而卻步!

于是就想 有沒(méi)有 在不耽誤數(shù)據(jù)交互的情況下,而又能降低服務(wù)器負(fù)擔(dān)的方法呢!

一個(gè)網(wǎng)站,訪問(wèn)量最大的莫過(guò)于 首頁(yè) 和主欄目頁(yè)了。 其他的頁(yè)面 我可以不去想, 首頁(yè)和主欄目頁(yè) 在大流量下服務(wù)器改如何承擔(dān)呢。

根據(jù)我編程2年多來(lái)的總結(jié)經(jīng)驗(yàn)我想去了一下方法!

不生成靜態(tài)頁(yè) 并且降低服務(wù)器負(fù)擔(dān)!
復(fù)制代碼 代碼如下:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
'讀取遠(yuǎn)程文件的函數(shù)
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
'編碼轉(zhuǎn)換
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
                '先試圖訪問(wèn)緩存,看有沒(méi)有,或者過(guò)期沒(méi)有
    dateVal = Application("defaultdate")
    If dateVal = "" Then dateVal = DateAdd("s",1200,Now)
    If Application("default") <> "" Then
        If DateDiff("s", Now, dateVal) > 0 Then
                                                '如果有,就從緩存讀取,對(duì)服務(wù)器來(lái)說(shuō),就是從內(nèi)存讀取
            tobody = Application("default")&"<!--new cache"&dateVal&"-->"
            Exit Function
        End If
    End If
    Dim body
                '如果緩存沒(méi)有,則從遠(yuǎn)程讀取,并寫入緩存,設(shè)置緩存時(shí)間。
    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())
%>

相關(guān)文章

最新評(píng)論