利用 cache 做对比静态页的网页技术
网络编程 2021-07-05 10:58www.168986.cn编程入门
一直想写一套生成静态页面的文章系统 但面对生成静态后的一些复杂数据库交互问题。又望而却步!
于是就想 有没有 在不耽误数据交互的情况下,而又能降低服务器负担的方法呢!
一个网站,访问量最大的莫过于 首页 和主栏目页了。 其他的页面 我可以不去想, 首页和主栏目页 在大流量下服务器改如何承担呢。
根据我编程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://.aoaob./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())
%>
于是就想 有没有 在不耽误数据交互的情况下,而又能降低服务器负担的方法呢!
一个网站,访问量最大的莫过于 首页 和主栏目页了。 其他的页面 我可以不去想, 首页和主栏目页 在大流量下服务器改如何承担呢。
根据我编程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://.aoaob./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())
%>
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程