复制代码 代码如下:
<%
Rem=================================================================
Rem=类:CacheCls
Rem=说明:缓存的应用
Rem=Revision:1.01Beta
Rem=作者:熊氏英雄(cexo255)
Rem=Date:2005/05/618:38:10
Rem=QQ:30133499
Rem=MySite:Http://www.Relaxlife.net
Rem=下载:Http://www.Relaxlife.net/cexo/Cache_pro.rar
Rem=QQ群:4341998
Rem=适用:对一些常用到,而又不常改变的数据放入缓存中,调用速度要比每次都要从数据库中读要快N陪
Rem=================================================================
CacheName="RL"
ClassCacheCls
PrivateLocalCacheName,Cache_Data
PublicPropertyLetName(ByValvNewValue)
LocalCacheName=LCase(vNewValue)
Cache_Data=Application(CacheName&"_"&LocalCacheName)
EndProperty
PublicPropertyLetValue(ByValvNewValue)
DimN,i,NewValueArr
IfLocalCacheName<>""Then
N=CountInStr(vNewValue,"|")
NewValueArr=Split(vNewValue,"|",-1,1)
ReDimCache_Data(N)
Fori=0toN
Cache_Data(i)=NewValueArr(i)
Next
Application.Lock
Application(CacheName&"_"&LocalCacheName)=Cache_Data
Application.unLock
Else
Response.Write"设置缓存出错,或缓存名不能为空,请重新更新缓存"
Response.End()
EndIf
EndProperty
PublicPropertyGetValue()
IfLocalCacheName<>""Then
IfIsArray(Cache_Data)Then
Value=Cache_Data
EndIf
Else
Response.Write"设置缓存出错,或缓存名不能为空,请重新更新缓存"
Response.End()
EndIf
EndProperty
'取指定缓存中的值
PublicFunctionGetCacheValue(MyCaheName)
GetCacheValue=Application(CacheName&"_"&MyCaheName)
EndFunction
'取所有缓存名
PublicFunctionGetallCacheName()
DimCacheobj
ForEachCacheobjinApplication.Contents
GetallCacheName=GetallCacheName&Cacheobj&","
Next
GetallCacheName=Left(GetallCacheName,Len(GetallCacheName)-1)
GetallCacheName=Replace(GetallCacheName,CacheName&"_","")
EndFunction
'释放缓存
PublicSubDelCahe(MyCaheName)
Application.Lock
Application.Contents.Remove(CacheName&"_"&MyCaheName)
Application.unLock
EndSub
'释放所有缓存
PublicSubRemoveAllCache()
DimCachelist,i
Cachelist=Split(GetallCacheName(),",")
IfUBound(Cachelist)>0Then
Fori=0toUBound(Cachelist)
DelCaheCachelist(i)
Next
EndIf
EndSub
'统计字符Char在Str中出现的次数
PrivateFunctionCountInStr(Str,Char)
CountInStr=0
Dimi,CharLen
CharLen=Len(Char)
Fori=1toLen(Str)
IfMid(Str,i,CharLen)=CharThenCountInStr=CountInStr+1
Next
EndFunction
EndClass
DimCachePro
SetCachePro=NewCacheCls
'设置缓存“cexo255”和它的值:"cexo2551|cexo2552|cexo2553|cexo2554|cexo2555"
CachePro.Name="cexo255"
CachePro.Value="cexo2551|cexo2552|cexo2553|cexo2554|cexo2555"
'取当前缓存中的值
'CacheArr=CachePro.Value
CachePro.Name="wxf"
CachePro.Value="wxf"
CachePro.Name="dw"
CachePro.Value="dw"
'释放缓存cexo255
'CachePro.DelCahe("cexo255")
'释放所有缓存
'CachePro.RemoveAllCache
'取cexo255缓存中的值
CacheArr=CachePro.GetCacheValue("cexo255")
IfisArray(CacheArr)Then
Fori=0toUBound(CacheArr)
Response.WriteCacheArr(i)&"<br>"
Next
Else
Response.Write"缓存被释放!!!"
Endif
SetCachePro=Nothing
%>
【CacheCls缓存的应用】相关文章:
★ asp缓存类