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

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

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

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

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

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

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

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
'讀取遠程文件的函數(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
                '先試圖訪問緩存,看有沒有,或者過期沒有
    dateVal = Application("defaultdate")
    If dateVal = "" Then dateVal = DateAdd("s",1200,Now)
    If Application("default") <> "" Then
        If DateDiff("s", Now, dateVal) > 0 Then
                                                '如果有,就從緩存讀取,對服務(wù)器來說,就是從內(nèi)存讀取
            tobody = Application("default")&"<!--new cache"&dateVal&"-->"
            Exit Function
        End If
    End If
    Dim body
                '如果緩存沒有,則從遠程讀取,并寫入緩存,設(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)文章

最新評論