復制代碼 代碼如下:
<%
Rem =================================================================
Rem = 類:CacheCls
Rem = 說明:緩存的應用
Rem = Revision:1.01 Beta
Rem = 作者:熊氏英雄(cexo255)
Rem = Date:2005/05/6 18: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"
Class CacheCls
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 "設置緩存出錯,或緩存名不能為空,請重新更新緩存"
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 "設置緩存出錯,或緩存名不能為空,請重新更新緩存"
Response.End()
End If
End Property
'取指定緩存中的值
Public Function GetCacheValue(MyCaheName)
GetCacheValue = Application(CacheName & "_" & MyCaheName)
End Function
'取所有緩存名
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
'釋放緩存
Public Sub DelCahe(MyCaheName)
Application.Lock
Application.Contents.Remove(CacheName & "_" & MyCaheName)
Application.unLock
End Sub
'釋放所有緩存
Public Sub RemoveAllCache()
Dim Cachelist,i
Cachelist=Split(GetallCacheName(),",")
If UBound(Cachelist)>0 Then
For i=0 to UBound(Cachelist)
DelCahe Cachelist(i)
Next
End If
End Sub
'統計字符Char在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
'設置緩存“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")
If isArray(CacheArr) Then
For i = 0 to UBound(CacheArr)
Response.Write CacheArr(i) & "<br>"
Next
Else
Response.Write "緩存被釋放!!!"
End if
Set CachePro = Nothing
%>