一下是将数据库内容写入缓存.然后用FOR遍历替换Content的内容Function ReplaceAllLabel(Content)
dim Node
Call LoadLabelToCache()    '加载标签
For Each Node in Application(KS.SiteSN&"_labellist").documentElement.SelectNodes("labellist")
Content=Replace(Content,Node.selectSingleNode("@labelname").text,Node.text)
Next

'替换自定义函数标签 
Dim DCls:Set Dcls=New DIYCls
Content=DCls.ReplaceUserFunctionLabel(Content) 
Set DCls=nothing
ReplaceAllLabel =Content
End Function
'加载数据库的所有标签到缓存
 Sub LoadLabelToCache()
If Not IsObject(Application(KS.SiteSN&"_labellist")) Then
Set  Application(KS.SiteSN&"_labellist")=Server.CreateObject("msxml2.FreeThreadedDOMDocument"& MsxmlVersion)
Application(KS.SiteSN&"_labellist").appendChild(Application(KS.SiteSN&"_labellist").createElement("xml"))
Dim i,SQL,Node
Dim RS:Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open "Select ID,LabelType,LabelName,LabelContent from KS_Label Where LabelType<>5", Conn, 1, 1
If Not RS.Eof Then SQL=RS.GetRows(-1)
RS.Close:Set RS = Nothing
If IsArray(SQL) Then
for i=0 to Ubound(SQL,2)
 Set Node=Application(KS.SiteSN&"_labellist").documentElement.appendChild(Application(KS.SiteSN&"_labellist").createNode(1,"labellist",""))
 Node.attributes.setNamedItem(Application(KS.SiteSN&"_labellist").createNode(2,"labelname","")).text=SQL(2,I)
 Node.attributes.setNamedItem(Application(KS.SiteSN&"_labellist").createNode(2,"labelid","")).text=SQL(0,I)
If SQL(1,I) = 1 Then
 Node.text=ReplaceFreeLabel(SQL(3,I))
Else
 Node.text=Replace(SQL(3,I),")}","," & SQL(0,I) &")}")
End IF
next
End If
End if
End Sub

解决方案 »

  1.   

    上面用的是Application变量
    但是.NET里面有Cache.不知道用哪个更好.
    麻烦高手帮我转下上面代码.立刻给分.
      

  2.   

    asp.net里面也有个Application,Cache比Application灵活,但是使用难度大一点。
      

  3.   

    二、应用程序缓存1.创建方法1:Cache["CacheName"] = "CacheValue";
    方法2:Cache.Insert(String key,object value,System.Web.Caching.CacheDependency dependencies,DateTime absoluteExpiration,TimeSpan slidingExpiration,System.Web.Caching.CacheItemPriority priority,System.Web.Caching.CacheItemRemovedCallback onRemoveCallback);
    方法3:Cache.Add(String key,object value,System.Web.Caching.CacheDependency dependencies,DateTime absoluteExpiration,TimeSpan slidingExpiration,System.Web.Caching.CacheItemPriority priority,System.Web.Caching.CacheItemRemovedCallback onRemoveCallback);Add方法和Insert方法的区别是Add 方法将返回您添加到缓存中的对象。另外,如果使用 Add 方法,并且缓存中已经存在与现有项同名的项,则该方法不会替换该项,并且不会引发异常。创建示例①通过使用 Insert 方法将项添加到缓存中:  程序代码
    Cache.Insert("CacheItem2", "Cached Item 2");②通过指定依赖项向缓存添加项:  程序代码
    string[] dependencies = { "CacheItem2" };
    Cache.Insert("CacheItem3", "Cached Item 3",new System.Web.Caching.CacheDependency(null, dependencies));③将设有过期策略的项添加到缓存中:  程序代码
    Cache.Insert("CacheItem6", "Cached Item 6",null, DateTime.Now.AddMinutes(1d), System.Web.Caching.Cache.NoSlidingExpiration);④将设有优先级设置的项添加到缓存中:  程序代码
    Cache.Insert("CacheItem8", "Cached Item 8",
        null, System.Web.Caching.Cache.NoAbsoluteExpiration,
        System.Web.Caching.Cache.NoSlidingExpiration,
        System.Web.Caching.CacheItemPriority.High, null);2.检索  程序代码
    string cachedString;
    cachedString = (string)Cache["CacheItem"];
    if (cachedString == null)
    {
      cachedString = "Www.Mzwu.Com";
      Cache.Insert("CacheItem", cachedString);
    }注:由于缓存中所存储的信息为易失信息,即该信息可能由 ASP.NET 移除,因此建议的开发模式是首先确定该项是否在缓存中。如果不在,则应将它重新添加到缓存中,然后检索该项。3.移除  程序代码
    Cache.Remove("MyData1");