<%
=========================================
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
%>
ASP的XML缓存类,代替了Application-ASP教程,ASP应用
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP的XML缓存类,代替了Application-ASP教程,ASP应用
相关推荐
-      ASP 简介
-      SQL注入天书 – ASP注入漏洞全接触
-      用.net 处理xmlHttp发送异步请求
-      asp.net创建文件夹的IO类的问题
-      如何实现ASP.NET网站个性化
-      关于ASP.NET调用JavaScript的实现
-      ASP利用Google实现在线翻译功能
-      Asp无组件生成缩略图