分享你我的心得.
共乘一片美好网络.

ASP分页代码类

<%
‘=========================================
‘ ClassName: RyM_ClsCache
‘ Version: 1.0
‘ Date: 2006-8-2
‘ Author: 网海の求生
‘=========================================
‘ 调用说明:
‘ Set CC = New RyM_ClsCache ‘创建对象
‘ CC.CreateXmlObj "Temp.xml","/ROYAH_CACHE"
‘ CC.Name = "CA" ‘设置缓存名
‘ If CC.IsXmlObj() Then ‘如果存在缓存则
‘ Temp = CC.Value ‘直接xml中读取值
‘ Else 否则
‘ Temp = "要缓存的内容,只能是字符串"
‘ CC.Value = Temp ‘把要缓存的值写入xml
‘ End If
‘ Set CC = Nothing ‘释放对象
‘ 变量Temp就是经过缓存后的字符串值了
‘=========================================
Class RyM_ClsCache
Public Reloadtime
Private XmlDom, XmlDoc, XmlNode, XmlAttr, AttrTime
Private CacheName, LocalCacheName, XmlPath
Private Sub Class_Initialize()
Reloadtime = 14400
End Sub
Private Sub Class_Terminate()
Close()
End Sub
‘新建文本文件
Private Function SaveToFile(ByVal strBody,ByVal SavePath)
Set ObjStream = Server.CreateObject("ADODB.Stream")
ObjStream.Open
ObjStream.Type = 2
ObjStream.Charset = "GB2312"
ObjStream.WriteText strBody
ObjStream.SaveToFile SavePath,2
ObjStream.Close
Set ObjStream = Nothing
End Function
‘创建Xml对象
Public Sub CreateXmlObj(ByVal XmlName, ByVal ChName)
Set XmlDom = Server.CreateObject("Microsoft.FreeThreadedXMLDOM")
XmlPath = Server.MapPath(XmlName)
CacheName = ChName
If Not XmlDom.Load(XmlPath) Then ‘如果指定的缓存文件不存在则自动新建
SaveToFile "<?xml version=""1.0"" encoding=""GB2312""?><ROYAH_CACHE></ROYAH_CACHE>",XmlPath
XmlDom.Load(XmlPath)
End If
End Sub
‘设置返回数据节点名
Public Property Let Name(ByVal vNewValue)
LocalCacheName = vNewValue
If LocalCacheName <> "" Then
Set XmlDoc = XmlDom.documentElement.selectSingleNode(CacheName & "/" & LocalCacheName)
End If
End Property
‘设置当前节点值
Public Property Let Value(ByVal vNewValue)
If (XmlDoc Is Nothing) Then
Set XmlDoc = XmlDom.documentElement.selectSingleNode(CacheName)
Set XmlNode = XmlDom.createElement(LocalCacheName)
Set XmlAttr = XmlDom.createAttribute("Time")
XmlNode.Text = vNewValue
XmlAttr.Text = Now()
XmlDoc.AppendChild(XmlNode)
XmlNode.setAttributeNode XmlAttr
XmlDom.Save(XmlPath)
Else
XmlDoc.Text = vNewValue
Set AttrTime = XmlDoc.selectSingleNode("./@Time")
AttrTime.Text = Now()
XmlDom.Save(XmlPath)
End If
End Property
‘返回当前节点值
Public Property Get Value()
If Not (XmlDoc Is Nothing) Then
Value = XmlDoc.Text
End If
End Property
‘移除当前节点
Public Sub Remove()
If Not (XmlDoc Is Nothing) Then
XmlDoc.ParentNode.RemoveChild(XmlDoc)
XmlDom.Save(XmlPath)
End If
End Sub
‘检测当前节点是否存在
Public Function IsXmlObj()
IsXmlObj = False
If Not (XmlDoc Is Nothing) Then
IsXmlObj = True
Set AttrTime = XmlDoc.selectSingleNode("./@Time")
If DateDiff("s",CDate(AttrTime.Text),Now()) > (60*Reloadtime) Then IsXmlObj = False
End If
End Function
‘释放全部对象
Public Sub Close()
If IsObject(XmlDom) Then Set XmlDom = Nothing
If IsObject(XmlDoc) Then Set XmlDoc = Nothing
If IsObject(XmlNode) Then Set XmlNode = Nothing
If IsObject(XmlAttr) Then Set XmlAttr = Nothing
If IsObject(AttrTime) Then Set XmlAttr = Nothing
End Sub
End Class
%>
 

赞(0)
未经允许不得转载:小叶白龙博客 » ASP分页代码类
分享到: 更多 (0)

评论 1908

评论前必须登录!