实践xml缓存技术构建高性能web站点(4)
setcache.asp
相关代码
<%
openconn
Dim action
action = Trim(Request("action"))&""
Dim curpage
curpage = Request("curpage")
Dim classid
Dim keyword
Dim thmid
If action = "list" Then
classid = Request("classid")
If classid="" Or (Not IsNumeric(classid)) Or curpage="" Or (Not IsNumeric(curpage)) Then
Else
CreateListxml CLng(classid),CLng(curpage),20,10,60 * 60 * 2 '创建分类的xml
End If
ElseIf action = "search" Then
keyword = Trim(Request("keyword"))
If keyword="" Then
Else
CreateSearchxml keyword,CLng(curpage),20,10,60 * 60 * 2 '创建搜索的xml
End If
ElseIf action = "detail" Then
thmid = Request("id")
If thmid="" Or (Not IsNumeric(thmid)) Then
Else
CreateDetailxml CLng(thmid),60 * 60 * 2 '创建详情的xml
End If
End If
Call Closeconn
Response.write " "
Response.End
%>
至此,核心代码都分享出来了,实践证明,通过这样的方式,我的138手机主题网的服务器的CPU占用率和内存占用率明显下降,访问速度也明显提高,从以前的需要几秒甚至10多秒,到现在只需要10几毫秒。
为了方便大家理解其中的代码,我特地做了一个demo,供同行学习交流。地址:http://www.shouji138.com/aspnet2/demo
此例程的完整下载包:http://www.shouji138.com/aspnet2/demo/xmlcachedemo.rar