實踐xml緩存技術構建高性能web站點

打造一個高性能穩定的web站點一直是站長和程序員的夢想,本文用作者的一次親身經曆的來說說如何利用xml緩存技術實現站點的高性能。我是從今年開始做138手機主題網的,采用SQL2000做爲數據庫,開發語言用的是Asp,查詢的時候都是動態查詢,直接用like %的方式,那個時候反正一天的訪問量小,同時在線的時候也就幾十個人而已,所以服務器也就能勝任要求,隨著訪問量慢慢增加,當同時在線達到幾百人時,此時服務器開始不堪重負,CPU常常達到100%不降,網頁打開速度也超級慢,一個查詢頁面需要幾秒鍾甚至更長,于是我開始考慮優化程序和數據庫,數據庫建立索引,不是很理想,因爲用的是like '% 這種方式,于是我想到了緩存,而xml本身的特點決定了他非常適合做數據庫的緩存,好東西不敢獨享,特發布出來,以便同行交流,共同進步。

實現的思路是這樣的:程序讀取信息時,先判斷是否緩存了xml數據,如果有,則直接從xml中讀取信息,否則從數據庫中讀取,並將此次結果生成xml文件,以便以後調用,加快速度,同時判斷xml緩存文件是否過期,如果過期則需要重新生成xml。下面是具體的代碼。

xmlcachecls.asp

<%

Rem xml數據緩存類

'--------------------------------------------------

'轉載的時候請保留版權信息

'作者:walkman

'網址:手機主題 http://www.shouji138.com

'版本:ver1.0

'歡迎各位交流進步

'--------------------------------------------------

Class XmlCacheCls

Rem 私有變量定義

Private m_CacheTime '緩存時間,單位秒

Private m_PageSize '每頁大小

Private m_CachePageNum 'xml緩存頁大小

Private m_XmlFile 'xml路徑,用絕對地址,不需要加擴展名

Private m_Sql 'SQL語句

Private m_TableName '表名或者視圖名

Private m_Columns '列名 用,隔開

Private m_CurPage '當前頁

Private m_CacheType '緩存類型:1,列表 2,詳情

Private m_DataConn '數據源,必須已經打開

Private m_QueryType '查詢類型:1,直接用sql 2,用存儲過程

Private m_SQLArr '返回的數據數組

Private m_RecordCount

Rem 公共屬性

'緩存時間

Public Property Let CacheTime(v)

m_CacheTime = v

End Property

Public Property Get CacheTime

CacheTime = m_CacheTime

End Property

'每頁大小

Public Property Let PageSize(v)

m_PageSize = v

End Property

Public Property Get PageSize

PageSize = m_PageSize

End Property

'xml緩存頁大小

Public Property Let CachePageNum(v)

m_CachePageNum = v

End Property

Public Property Get CachePageNum

CachePageNum = m_CachePageNum

End Property

'xml路徑,用絕對地址

Public Property Let XmlFile(v)

m_XmlFile = v

End Property

Public Property Get XmlFile

XmlFile = m_XmlFile

End Property

'xml路徑,用絕對地址

'http://www.knowsky.com/article.asp?typeid=2

Public Property Let Sql(v)

m_Sql = v

End Property

Public Property Get Sql

Sql = m_Sql

End Property

'表名或者視圖名

Public Property Let TableName(v)

m_TableName = v

End Property

Public Property Get TableName

TableName = m_TableName

End Property

'列名 用,隔開

Public Property Let Columns(v)

m_Columns = v

End Property

Public Property Get Columns

Columns = m_Columns

End Property

'當前頁

Public Property Let CurPage(v)

m_CurPage = v

End Property

Public Property Get CurPage

CurPage = m_CurPage

End Property

'緩存類型:1,列表 2,詳情

Public Property Let CacheType(v)

m_CacheType = v

End Property

Public Property Get CacheType

CacheType = m_CacheType

End Property

'緩存類型:1,列表 2,詳情

Public Property Set Conn(v)

Set m_DataConn = v

End Property

Public Property Get Conn

Conn = m_DataConn

End Property

'返回記錄總數

Public Property Get RecordCount

RecordCount = m_RecordCount

End Property

'返回記錄數組

'http://www.devdao.com/

Public Property Get SQLArr

SQLArr = m_SQLArr

End Property

Rem 公共方法 讀取數據

Public Function ReadData

If m_CacheType = 1 Then

ReadListAndSearchData

Else

ReadContentData

End If

End Function

Rem 讀取詳情信息

Private Function ReadContentData

Dim xmlfile

xmlfile = m_XmlFile

If FSOExistsFile(xmlfile) Then '存在xml緩存,直接從xml中讀取

ReadContentDataFromXml xmlfile

Else

ReadContentDataFromDB

End If

End Function

Rem 從xml文件讀取詳情信息

Private Function ReadContentDataFromXml(xmlfile)

Dim SQLARR()

Dim XmlDoc

Set XmlDoc = Server.CreateObject("msxml2.FreeThreadedDOMDocument.3.0")

XmlDoc.Load xmlfile

Dim itemslength,itemsi

itemslength = XmlDoc.documentElement.childNodes.length

For itemsi=0 To itemslength-1

ReDim Preserve SQLARR(itemslength-1,0)

SQLARR(itemsi,0) = XmlDoc.documentElement.childNodes(itemsi).text

Next

Set XmlDoc = Nothing

m_SQLArr = SQLArr

End Function

Rem 從Db中讀取詳情信息

Private Function ReadContentDataFromDB()

Dim rs

Dim SQLARR

Set rs = m_DataConn.execute(m_sql)

IF Not Rs.eof Then

SQLArr=Rs.GetRows(1)

rs.close

Set rs = Nothing

Else

rs.close

Set rs = Nothing

Exit Function

End If

m_SQLArr = SQLArr

End Function

Rem 讀取列表數據

Private Function ReadListAndSearchData

Dim sPagesize,TotalPage,CurPage,TotalRec

sPagesize = m_PageSize * m_CachePageNum

m_CurPage = CLng(m_CurPage)

If m_CurPage Mod m_CachePageNum = 0 Then

CurPage = m_CurPage/m_CachePageNum

Else

CurPage = int(clng(m_CurPage)/m_CachePageNum)+1

End If

Dim xmlfile

xmlfile = getXmlFileName(CurPage)

If FSOExistsFile(xmlfile) Then '存在xml緩存,直接從xml中讀取

ReadListAndSearchDataFromXml xmlfile

Else

ReadListAndSearchDataFromDB

End If

End Function

Rem 從xml中讀列表數據

Private Function ReadListAndSearchDataFromXml(xmlfile)

Dim SQLARR()

Dim XmlDoc

Set XmlDoc = Server.CreateObject("msxml2.FreeThreadedDOMDocument.3.0")

XmlDoc.Load xmlfile

Dim totalrecont

totalrecont = XmlDoc.documentElement.selectSingleNode("totalrec").text

m_RecordCount = totalrecont

Dim TotalRec

TotalRec = m_RecordCount

If totalrecont = 0 Then

Set XmlDoc = Nothing

m_SQLArr = SQLARR

Exit Function

End If

Dim TotalPage,curpage

curpage = m_CurPage

If m_CurPage Mod m_CachePageNum = 0 Then

CurPage = m_CurPage/m_CachePageNum

Else

CurPage = int(clng(m_CurPage)/m_CachePageNum)+1

End If

If TotalRec Mod m_CachePageNum =0 Then

TotalPage = totalrecont/m_CachePageNum

Else

TotalPage = int(clng(totalrecont)/m_CachePageNum)+1

End If

If curpage>TotalPage Then curpage=TotalPage

Dim starti

Dim startn

startn = m_curpage - (curpage-1) * m_CachePageNum

Rem 計算開始位置

starti = (startn-1) * m_pagesize

Dim items,item

Set items = XmlDoc.documentElement.SelectNodes("item")

Dim i

Dim num

Dim length

length = items.length

num = 0

For i = starti To m_PageSize + starti -1

If i >=length Then Exit For

Set item = items(i)

Dim attrlength

attrlength = item.attributes.length

ReDim Preserve SQLARR(attrlength,num)

Dim Attribute

Dim Attributei

Attributei = 0

For Attributei = 0 To attrlength-1

SQLArr(Attributei,num) = item.attributes(Attributei).Nodevalue

Next

num = num + 1

Next

Set XmlDoc = Nothing

m_SQLArr = SQLArr

End Function

Rem 從DB中讀列表數據

Private Function ReadListAndSearchDataFromDB

Dim rs,TotalRec,CurPage

CurPage = m_CurPage

Set Rs = Server.CreateObject("Adodb.Recordset")

Rs.open m_sql,m_DataConn,1

TotalRec = rs.recordcount

m_RecordCount = TotalRec

rs.pagesize = m_PageSize

If CurPage>rs.PageCount Then CurPage = rs.PageCount

If Not rs.eof Then rs.absolutePage=m_CurPage

Dim SQLARR()

Dim k

k = 0

While Not rs.eof and k<m_PageSize

Dim fieldlegth

fieldlegth = rs.Fields.count

ReDim Preserve SQLARR(fieldlegth,k)

Dim fieldi

For fieldi = 0 To fieldlegth-1

SQLArr(fieldi,k) = rs.Fields(fieldi).value

Next

rs.movenext

k=k+1

Wend

rs.close

Set rs = Nothing

m_SQLArr = SQLArr

End Function

Rem 獲取xml文件名稱

Private Function getXmlFileName(num)

Dim tmpstr

tmpstr = LCase(m_XmlFile)

If Right(tmpstr,4) = ".xml" Then

tmpstr = Left(tmpstr,Len(tmpstr)-Len(".xml"))

End If

tmpstr = Replace(tmpstr,"%","_")

tmpstr = tmpstr & "_" & num & ".xml"

getXmlFileName = tmpstr

End Function

Rem 公共方法 將數據寫入xml文件

Public Function WriteDataToXml

If m_CacheType = 1 Then

WriteListAndSearchDataToXml

Else

WriteContentDataToXml

End If

End Function

Rem 寫具體某條信息的詳情xml

Private Function WriteContentDataToXml

Rem xml未過期則直接退出

Dim xmlfile

xmlfile = m_XmlFile

If FSOExistsFile(xmlfile) Then

If Not isXmlCacheExpired(xmlfile,m_CacheTime) Then Exit Function

End If

Dim rs

Set rs = Server.CreateObject("Adodb.Recordset")

Rs.open m_sql,m_DataConn

CreateContentXmlFile xmlfile,Rs

End Function

Rem 列表和搜索xml數據

Private Function WriteListAndSearchDataToXml

Dim sPagesize,TotalPage,CurPage,TotalRec

sPagesize = m_PageSize * m_CachePageNum

m_CurPage = CLng(m_CurPage)

If m_CurPage Mod m_CachePageNum = 0 Then

CurPage = m_CurPage/m_CachePageNum

Else

CurPage = int(clng(m_CurPage)/m_CachePageNum)+1

End If

Dim xmlfile

xmlfile = getXmlFileName(CurPage)

Rem 如果xml未過期則直接退出

If FSOExistsFile(xmlfile) Then

If Not isXmlCacheExpired(xmlfile,m_CacheTime) Then Exit Function

End If

Dim rs

Set Rs = Server.CreateObject("Adodb.Recordset")

Rs.open m_sql,m_DataConn,1

TotalRec = rs.recordcount

rs.pagesize = sPagesize

If CurPage>rs.PageCount Then CurPage = rs.PageCount

CreateListAndSearchXMLFile xmlfile,TotalRec,Rs,sPagesize

End Function

Rem 私有方法

Rem 得到文件的最後修改時間

Private Function FSOGetFileLastModifiedTime(file)

Dim fso,f,s

Set fso=CreateObject("Scripting.FileSystemObject")

Set f=fso.GetFile(file)

FSOGetFileLastModifiedTime = f.DateLastModified

Set f = Nothing

Set fso = Nothing

End Function

Rem 判斷xml緩存是否到期

Private Function isXmlCacheExpired(file,seconds)

Dim filelasttime

filelasttime = FSOGetFileLastModifiedTime(file)

If DateAdd("s",seconds,filelasttime) < Now Then

isXmlCacheExpired = True

Else

isXmlCacheExpired = False

End If

End Function

Rem 文件是否存在

Private Function FSOExistsFile(file)

Dim fso

Set fso = Server.CreateObject("Scripting.FileSystemObject")

If fso.FileExists(file) Then

FSOExistsFile = true

Else

FSOExistsFile = false

End If

Set fso = nothing

End Function

Rem 生成詳細數據的xml

Private Function CreateContentXmlFile(xmlfile,Rs)

Dim xmlcontent

xmlcontent = "<?xml version=""1.0"" encoding=""gb2312""?>" & vbnewline

xmlcontent = xmlcontent & "<root>" & vbnewline

Dim field

For Each field In rs.Fields

xmlcontent = xmlcontent & "<"&field.name&">"

Dim value

value = field.value

If TypeName(value) = "String" Then

xmlcontent = xmlcontent & "<![CDATA[" & Trim(value) & "]]>"

Else

xmlcontent = xmlcontent & Trim(value)

End If

xmlcontent = xmlcontent & "</"&field.name&">" & vbnewline

Next

rs.close

Set rs = Nothing

xmlcontent = xmlcontent & "</root>" & vbnewline

Dim folderpath

folderpath = Trim(left(xmlfile,InstrRev(xmlfile,"\")-1))

Call CreateDIR(folderpath&"") '創建文件夾

WriteStringToXMLFile xmlfile,xmlcontent

End Function

Rem 生成列表的xml

Private Function CreateListAndSearchXMLFile(xmlfile,TotalRec,Rs,sPagesize)

Dim xmlcontent

xmlcontent = ""

xmlcontent = xmlcontent & "<?xml version=""1.0"" encoding=""gb2312""?>" & vbnewline

xmlcontent = xmlcontent & " <root>" & vbnewline

xmlcontent = xmlcontent & " <totalrec>" & TotalRec & "</totalrec>" & vbnewline

Dim k

k = 0

Dim field

While Not rs.eof and k<sPagesize

xmlcontent = xmlcontent & " <item "

For Each field In rs.Fields

xmlcontent = xmlcontent & field.name & "=""" & XMLStringEnCode(field.value) & """ "

Next

xmlcontent = xmlcontent & "></item>" & vbnewline

rs.movenext

k=k+1

Wend

rs.close

Set rs = Nothing

xmlcontent = xmlcontent & " </root>" & vbnewline

Dim folderpath

folderpath = Trim(left(xmlfile,InstrRev(xmlfile,"\")-1))

Call CreateDIR(folderpath&"") '創建文件夾

WriteStringToXMLFile xmlfile,xmlcontent

End Function

Rem xml轉義字符

Private Function XMLStringEnCode(str)

If str&"" = "" Then XMLStringEnCode="":Exit Function

str = Replace(str,"<","&lt;")

str = Replace(str,">","&gt;")

str = Replace(str,"'","&apos;")

str = Replace(str,"""","&quot;")

str = Replace(str,"&","&amp;")

XMLStringEnCode = str

End Function

Rem 寫文件

Private Sub WriteStringToXMLFile(filename,str)

'On Error Resume Next

Dim fs,ts

Set fs= createobject("scripting.filesystemobject")

If Not IsObject(fs) Then Exit Sub

Set ts=fs.OpenTextFile(filename,2,True)

ts.writeline(str)

ts.close

Set ts=Nothing

Set fs=Nothing

End Sub

Rem 創建文件夾

Private function CreateDIR(byval LocalPath)

On Error Resume Next

Dim i,FileObject,patharr,path_level,pathtmp,cpath

LocalPath = Replace(LocalPath,"\","/")

Set FileObject = server.createobject("Scripting.FileSystemObject")

patharr = Split(LocalPath,"/")

path_level = UBound (patharr)

For i = 0 To path_level

If i=0 Then

pathtmp=patharr(0) & "/"

Else

pathtmp = pathtmp & patharr(i) & "/"

End If

cpath = left(pathtmp,len(pathtmp)-1)

If Not FileObject.FolderExists(cpath) Then

'Response.write cpath

FileObject.CreateFolder cpath

End If

Next

Set FileObject = Nothing

If err.number<>0 Then

CreateDIR = False

err.Clear

Else

CreateDIR = True

End If

End Function

End Class

%>

此類包含兩種緩存方式:一種是基于列表方式的,如按照某個類別顯示信息、搜索某個關鍵詞進行顯示;另外一種是詳細頁面的緩存,如顯示具體的某篇文章。

此類與具體的業務邏輯無關,只負責xml數據的讀取和存儲,判斷是否緩存過期決定是否需要更新緩存。按照三層構架模式的話,它處于數據訪問層。

調用這個類的代碼:

Business.asp

<%

Rem xml數據緩存類業務邏輯層代碼

'--------------------------------------------------

'轉載的時候請保留版權信息

'作者:walkman

'網址:手機主題 http://www.shouji138.com

'版本:ver1.0

'歡迎各位交流進步

'--------------------------------------------------

Rem 根據classid取列表數據

Function GetListarr(classid,curpage,PageSize,CachePageNum,ByRef RecordCount)

openConn

Dim sql

sql = "select thmid,thmname,picfileurl,win_theme.adddate from win_theme where win_theme.ClassID="&classid&" order by thmid desc"

Dim cache

Set cache = new XmlCacheCls

cache.PageSize = PageSize '每頁N條記錄

cache.CachePageNum = CachePageNum '一個xml文件緩存M頁的數據量

cache.XmlFile = Server.Mappath("xmlcache/classxml/list_"&classid&".xml")

cache.Sql = sql

cache.CurPage = curpage

cache.CacheType = 1

Set cache.Conn = conn

cache.ReadData

Dim SqlArr

SQLArr = cache.SQLArr

RecordCount = cache.RecordCount

Set cache = Nothing

GetListarr = SqlArr

End Function

Rem 根據classid生成xml緩存

Function CreateListxml(classid,curpage,PageSize,CachePageNum,CacheTime)

Dim sql

sql = "select thmid,thmname,picfileurl,win_theme.adddate from win_theme where win_theme.ClassID="&classid&" order by thmid desc"

Dim cache

Set cache = new XmlCacheCls

cache.CacheTime = CacheTime '緩存時間

cache.PageSize = PageSize '每頁N條記錄

cache.CachePageNum = CachePageNum '一個xml文件緩存M頁的數據量

cache.XmlFile = Server.Mappath("xmlcache/classxml/list_"&classid&".xml")

cache.Sql = sql

cache.CurPage = curpage

cache.CacheType = 1

Set cache.Conn = conn

cache.WriteDataToXml

Set cache = Nothing

End Function

Rem 根據keyword取列表數據

Function GetSearcharr(keyword,curpage,PageSize,CachePageNum,ByRef RecordCount)

openConn

Dim sql

Dim sqlkey

sqlkey = Replace(keyword,"'","")

sql = "select thmid,thmname,picfileurl,win_theme.adddate from win_theme where ThmName like '%"&sqlkey&"%' or ThmRange like '%"&sqlkey&"%' or ThmInstro like '%"&sqlkey&"%' order by thmid desc"

Dim cache

Set cache = new XmlCacheCls

cache.PageSize = PageSize '每頁N條記錄

cache.CachePageNum = CachePageNum '一個xml文件緩存M頁的數據量

cache.XmlFile = Server.Mappath("xmlcache/searchxml/list_"&Server.URlEncode(Replace(keyword,"'",""))&".xml")

cache.Sql = sql

cache.CurPage = curpage

cache.CacheType = 1

Set cache.Conn = conn

cache.ReadData

Dim SqlArr

SQLArr = cache.SQLArr

RecordCount = cache.RecordCount

Set cache = Nothing

GetSearcharr = SqlArr

End Function

Rem 根據keyword生成xml緩存

Function CreateSearchxml(keyword,curpage,PageSize,CachePageNum,CacheTime)

Dim sql

Dim sqlkey

sqlkey = Replace(keyword,"'","")

sql = "select thmid,thmname,picfileurl,win_theme.adddate from win_theme where ThmName like '%"&sqlkey&"%' or ThmRange like '%"&sqlkey&"%' or ThmInstro like '%"&sqlkey&"%' order by thmid desc"

Dim cache

Set cache = new XmlCacheCls

cache.CacheTime = CacheTime '緩存時間

cache.PageSize = PageSize '每頁N條記錄

cache.CachePageNum = CachePageNum '一個xml文件緩存M頁的數據量

cache.XmlFile = Server.Mappath("xmlcache/searchxml/list_"&Server.URlEncode(Replace(keyword,"'",""))&".xml")

cache.Sql = sql

cache.CurPage = curpage

cache.CacheType = 1

Set cache.Conn = conn

cache.WriteDataToXml

Set cache = Nothing

End Function

Rem 根據classid取列表數據

Function GetDetailarr(thmid)

openConn

Dim sql

sql = "select a.thmid,a.thmname,a.classid,b.classname,a.picfileurl,a.thmver,a.thmsize,a.thminstro,a.thmrange,a.thmfileurl,a.adddate from win_theme a,Win_Classify b where a.classid=b.classid and a.thmid="&thmid&""

Dim thmidmod

thmidmod = thmid Mod 100

Dim cache

Set cache = new XmlCacheCls

cache.XmlFile = Server.Mappath("xmlcache/detailxml/"&thmidmod&"/"&thmid&".xml")

cache.Sql = sql

cache.CacheType = 2

Set cache.Conn = conn

cache.ReadData

Dim SqlArr

SQLArr = cache.SQLArr

Set cache = Nothing

GetDetailarr = SqlArr

End Function

Rem 根據keyword生成xml緩存

Function CreateDetailxml(thmid,CacheTime)

Dim sql

sql = "select a.thmid,a.thmname,a.classid,b.classname,a.picfileurl,a.thmver,a.thmsize,a.thminstro,a.thmrange,a.thmfileurl,a.adddate from win_theme a,Win_Classify b where a.classid=b.classid and a.thmid="&thmid&""

Dim thmidmod

thmidmod = thmid Mod 100

Dim cache

Set cache = new XmlCacheCls

cache.CacheTime = CacheTime '緩存時間

cache.XmlFile = Server.Mappath("xmlcache/detailxml/"&thmidmod&"/"&thmid&".xml")

cache.Sql = sql

cache.CacheType = 2

Set cache.Conn = conn

cache.WriteDataToXml

Set cache = Nothing

End Function

Rem 檢測動態數組是否已分配

Function ismalloc(a)

On Error Resume Next

Dim i

i = UBound(a)

If Err Then

ismalloc = False

Else

ismalloc = True

End If

End Function

Function showData(SQLArr)

If Not ismalloc(SQLArr) Then Exit Function

Dim i,k

Dim num

num = 0

i = UBound(SQLArr,1)

k = UBound(SQLArr,2)

Dim m,n

For m = 0 To k

num = num+1

%>

<ul class="listbox" onMouseOver="overtb(this)" onMouseOut="outtb(this)">

<li>

<a title="<%=SQLArr(1,m)%>" href="detail.asp?id=<%=SQLArr(0,m)%>" target="_blank">

<img height="140" alt="<%=SQLArr(1,m)%>" src="http://www.shouji138.com<%=SQLArr(2,m)%>" width="107" border="0"></a>

</li>

<li class="green bold">

<a title="<%=SQLArr(1,m)%>" href="detail.asp?id=<%=SQLArr(0,m)%>" target="_blank">

<%=walkgottopic(Trim(SQLArr(1,m)),18)%></a>

</li>

<li><%=DateValue(SQLArr(3,m))%></li>

</ul>

<%

next

End Function

%>

這個文件是業務邏輯層代碼,負責根據不同的業務邏輯來實現xml數據的讀取和寫入,並提供接口方法給web表現層調用。

具體的調用代碼:

list.asp

只顯示相關代碼。

<%

。。。。。。

Dim classid

classid = Request("classid")

If classid = "" Or (Not IsNumeric(classid)) Then Response.write "參數錯誤!":Response.End()

classid = CLng(classid)

Dim sPagesize,TotalPage,CurPage,TotalRec,CachePageNum

sPagesize = 20

CachePageNum = 10

CurPage = Trim(Request("page"))

IF CurPage="" Or (Not IsNumeric(CurPage)) Then

CurPage=1

Else

CurPage=Clng(CurPage)

End IF

Dim myarr

myarr = GetListarr(classid,CurPage,sPagesize,CachePageNum,TotalRec)

'總頁數

TotalPage = int(clng(TotalRec)/sPagesize*-1)*-1

If Clng(TotalRec)>0 Then

showData myarr

End If

................

%>

最後在頁面最底部調用一個asp的script語句來更新xml緩存。

<script type="text/javascript" src="setcache.asp?action=list&curpage=<%=curpage%>&classid=<%=classid%>"></script>

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

本人QQ:441003232 歡迎大家交流共同進步。

也可以訪問本人的小站:手機主題:http://www.shouji138.com

 
構建基于Web/XML的信息集成研究
     摘要 在當前的網絡信息時代,信息量不僅龐大而且源自于不同的數據源,信息集成一直是研究的熱點。基于多代理(Multi-Agent)的信息資源集成方案有所不足,而XML集成機制的優點,適于網絡環境下基于XML的信息集...查看完整版>>構建基于Web/XML的信息集成研究
 
構建基于Web/XML的信息集成研究
摘要 在當前的網絡信息時代,信息量不僅龐大而且源自于不同的數據源,信息集成一直是研究的熱點。基于多代理(Multi-Agent)的信息資源集成方案有所不足,而XML集成機制的優點,適于網絡環境下基于XML的信息集成。本方...查看完整版>>構建基于Web/XML的信息集成研究
 
構建基于Web/XML的信息集成研究
  摘要 在當前的網絡信息時代,信息量不僅龐大而且源自于不同的數據源,信息集成一直是研究的熱點。基于多代理(Multi-Agent)的信息資源集成方案有所不足,而XML集成機制的優點,適于網絡環境下基于XML的信息集成。...查看完整版>>構建基于Web/XML的信息集成研究
 
基于Java&XML技術構建植物病蟲害遠程診斷系統
  摘要:利用Java&XML技術實現通過互聯網對植物病蟲害進行遠程診斷的功能,介紹該系統的結構、組成、發展方向,爲病蟲害防治提供服務。要害詞:J2EE,XML,MVC,遠程診斷1.引言 網絡服務已經影響到整個社會的方方面...查看完整版>>基于Java&XML技術構建植物病蟲害遠程診斷系統
 
XML與面向Web的數據挖掘技術
     面向Web的數據挖掘  Web上有海量的數據信息,怎樣對這些數據進行複雜的應用成了現今數據庫技術的研究熱點。數據挖掘就是從大量的數據中發現隱含的規律性的內容,解決數據的應用質量問題。充分利用有用的數...查看完整版>>XML與面向Web的數據挖掘技術