用户登录
用户注册

分享至

利用 cache 做对比静态页的网页技术

  • 作者: 回头看丶我在你身后_
  • 来源: 51数据库
  • 2021-10-05
一直想写一套生成静态页面的文章系统 但面对生成静态后的一些复杂数据库交互问题。又望而却步!

于是就想 有没有 在不耽误数据交互的情况下,而又能降低服务器负担的方法呢!

一个网站,访问量最大的莫过于 首页 和主栏目页了。 其他的页面 我可以不去想, 首页和主栏目页 在大流量下服务器改如何承担呢。

根据我编程2年多来的总结经验我想去了一下方法!

不生成静态页 并且降低服务器负担!
复制代码 代码如下:

<%@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())
%>
软件
前端设计
程序设计
Java相关