asp xml 缓存类

复制代码 代码如下:

<%
Rem xml缓存类
'--------------------------------------------------------------------
'转载的时候请保留版权信息
'作者:╰⑥月の雨╮
'版本:ver1.0
'本类部分借鉴 walkmanxml数据缓存类,使用更为方便 欢迎各位交流进步
'--------------------------------------------------------------------
Class XmlCacheCls
Private m_DataConn '数据源,必须已经打开
Private m_CacheTime '缓存时间,单位秒 默认10分钟
Private m_XmlFile 'xml路径,用绝对地址,不需要加扩展名
Private m_Sql 'SQL语句
Private m_SQLArr '(只读)返回的数据数组
Private m_ReadOn '(只读)返回读取方式 1-数据库 2-xml 检测用

'类的属性=========================================

'数据源
Public Property Set Conn(v)
Set m_DataConn = v
End Property
Public Property Get Conn
Conn = m_DataConn
End Property

'缓存时间
Public Property Let CacheTime(v)
m_CacheTime = v
End Property
Public Property Get CacheTime
CacheTime = m_CacheTime
End Property

'xml路径,用绝对地址
Public Property Let XmlFile(v)
m_XmlFile = v
End Property
Public Property Get XmlFile
XmlFile = m_XmlFile
End Property

'Sql语句
Public Property Let Sql(v)
m_Sql = v
End Property
Public Property Get Sql
Sql = m_Sql
End Property
'返回记录数组
Public Property Get SQLArr
SQLArr = m_SQLArr
End Property

'返回读取方式
Public Property Get ReadOn
ReadOn = m_ReadOn
End Property

'类的析构=========================================

Private Sub Class_Initialize() '初始化类
m_CacheTime=60*10 '默认缓存时间为10分钟
End Sub

Private Sub Class_Terminate() '释放类

End Sub

'类的公共方法=========================================

Rem 读取数据
Public Function ReadData
If FSOExistsFile(m_XmlFile) Then '存在xml缓存,直接从xml中读取
ReadDataFromXml
m_ReadOn=2
Else
ReadDataFromDB
m_ReadOn=1
End If
End Function

Rem 写入XML数据
Public Function WriteDataToXml
If FSOExistsFile(m_XmlFile) Then '如果xml未过期则直接退出
If Not isXmlCacheExpired(m_XmlFile,m_CacheTime) Then Exit Function
End If
Dim rs
Dim xmlcontent
Dim k
xmlcontent = ""
xmlcontent = xmlcontent & "<?xml version=""1.0"" encoding=""gb2312""?>" & vbnewline
xmlcontent = xmlcontent & " <root>" & vbnewline
k=0
Set Rs = Server.CreateObject("Adodb.Recordset")
Rs.open m_sql,m_DataConn,1
While Not rs.eof
xmlcontent = xmlcontent & " <item "
For Each field In rs.Fields
xmlcontent = xmlcontent & field.name & "=""" & XMLStringEnCode(field.value) & """ "
Next
rs.movenext
k=k+1
xmlcontent = xmlcontent & "></item>" & vbnewline

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/2891.html