<%
Rem ================================================= ================
Rem = class:CacheCls
Rem = Description: Cached application
Rem = Revision:1.01 Beta
Rem = Author: Xiong’s Hero (cexo255)
Rem = Date:2005/05/6 18:38:10
Rem = QQ:30133499
Rem = MySite:Http://www.Relaxlife.net
Rem = Download: Http://www.Relaxlife.net /cexo/Cache_pro.rar
Rem = QQ group: 4341998
Rem = Applicable: Put some commonly used but infrequently changed data into the cache, and the calling speed is faster than reading from the database every time.
Rem ================================================= ================
CacheName = "RL"
ClassCacheCls
Private LocalCacheName, Cache_Data
Public Property Let Name(ByVal vNewValue)
LocalCacheName = LCase(vNewValue)
Cache_Data=Application(CacheName & "_" & LocalCacheName)
End Property
Public Property Let Value(ByVal vNewValue)
Dim N,i,NewValueArr
If LocalCacheName<>"" Then
N = CountInStr(vNewValue,"|")
NewValueArr = Split(vNewValue,"|",-1,1)
ReDim Cache_Data(N)
For i = 0 to N
Cache_Data(i) = NewValueArr(i)
Next
Application.Lock
Application(CacheName & "_" & LocalCacheName) = Cache_Data
Application.unLock
Else
Response.Write "Error setting cache, or the cache name cannot be empty, please update the cache again"
Response.End()
End If
End Property
Public Property Get Value()
If LocalCacheName<>"" Then
If IsArray(Cache_Data) Then
Value=Cache_Data
End If
Else
Response.Write "Error setting cache, or the cache name cannot be empty, please update the cache again"
Response.End()
End If
End Property
'Get the value in the specified cache
Public Function GetCacheValue(MyCacheName)
GetCacheValue = Application(CacheName & "_" & MyCacheName)
End Function
'Get all cache names
Public Function GetallCacheName()
Dim Cacheobj
For Each Cacheobj in Application.Contents
GetallCacheName = GetallCacheName & Cacheobj & ","
Next
GetallCacheName = Left(GetallCacheName,Len(GetallCacheName)-1)
GetallCacheName = Replace(GetallCacheName,CacheName & "_","")
End Function
'Release cache
Public Sub DelCahe(MyCaheName)
Application.Lock
Application.Contents.Remove(CacheName & "_" & MyCacheName)
Application.unLock
End Sub
'Release all caches
Public Sub RemoveAllCache()
Dim Cachelist,i
Cachelist=Split(GetallCacheName(),",")
If UBound(Cachelist)>0 Then
For i=0 to UBound(Cachelist)
DelCache Cachelist(i)
Next
End If
End Sub
'Count the number of times the character Char appears in Str
Private Function CountInStr(Str,Char)
CountInStr = 0
Dim i,CharLen
CharLen = Len(Char)
For i = 1 to Len(Str)
If Mid(Str, i, CharLen) = Char Then CountInStr = CountInStr + 1
Next
End Function
End Class
Dim CachePro
Set CachePro = New CacheCls
'Set cache "cexo255" and its value: "cexo2551|cexo2552|cexo2553|cexo2554|cexo2555"
CachePro.Name = "cexo255"
CachePro.Value = "cexo2551|cexo2552|cexo2553|cexo2554|cexo2555"
'Get the value in the current cache
'CacheArr = CachePro.Value
CachePro.Name = "wxf"
CachePro.Value = "wxf"
CachePro.Name = "dw"
CachePro.Value = "dw"
'Release cache cexo255
'CachePro.DelCache("cexo255")
'Release all caches
'CachePro.RemoveAllCache
'Get the value in the cexo255 cache
CacheArr = CachePro.GetCacheValue("cexo255")
If isArray(CacheArr) Then
For i = 0 to UBound(CacheArr)
Response.Write CacheArr(i) & "<br>"
Next
Else
Response.Write "Cache released!!!"
End if
Set CachePro = Nothing
%>