asp 캐 시 클래스
11064 단어 asp 캐 시 클래스
'**********************************************
' vbs Cache
'
' valid, ,
' name,cache ,
' add( , ), cache
' value, cache
' blempty,
' makeEmpty, ,
' equal( 1), cache 1
' expires(time), time
' 2002.12.24
' http://www.aspsky.net/
'**********************************************
class Cache
private obj 'cache
private expireTime '
private expireTimeName ' application
private cacheName 'cache application
private path 'uri
private sub class_initialize()
path=request.servervariables("url")
path=left(path,instrRev(path,"/"))
end sub
private sub class_terminate()
end sub
public property get blEmpty
'
if isempty(obj) then
blEmpty=true
else
blEmpty=false
end if
end property
public property get valid
' ( )
if isempty(obj) or not isDate(expireTime) then
valid=false
elseif CDate(expireTime)<now then
valid=false
else
valid=true
end if
end property
public property let name(str)
' cache
cacheName=str & path
obj=application(cacheName)
expireTimeName=str & "expires" & path
expireTime=application(expireTimeName)
end property
public property let expires(tm)
'
expireTime=tm
application.lock
application(expireTimeName)=expireTime
application.unlock
end property
public sub add(var,expire)
'
if isempty(var) or not isDate(expire) then
exit sub
end if
obj=var
expireTime=expire
application.lock
application(cacheName)=obj
application(expireTimeName)=expireTime
application.unlock
end sub
public property get value
'
if isempty(obj) or not isDate(expireTime) then
value=null
elseif CDate(expireTime)<now then
value=null
else
value=obj
end if
end property
public sub makeEmpty()
' application
application.lock
application(cacheName)=empty
application(expireTimeName)=empty
application.unlock
obj=empty
expireTime=empty
end sub
public function equal(var2)
'
if typename(obj)<>typename(var2) then
equal=false
elseif typename(obj)="Object" then
if obj is var2 then
equal=true
else
equal=false
end if
elseif typename(obj)="Variant()" then
if join(obj,"^")=join(var2,"^") then
equal=true
else
equal=false
end if
else
if obj=var2 then
equal=true
else
equal=false
end if
end if
end function
end class
vbs Cache
'
' valid, ,
' name,cache ,
' add( , ), cache
' value, cache
' blempty,
' makeEmpty, ,
' DelCahe ,
' equal( 1), cache 1
' expires(time), time
'
set myCache=New Cache
myCache.name="BoardJumpList" '
if myCache.valid then ' ( , )
response.write myCache.value '
else
................
BoardJumpList=xxx
myCache.add BoardJumpList,dateadd("n",60,now) ' xxx.add ,
response.write BoardJumpList '
end if
myCache.makeEmpty()
mycache.DelCahe()
미 성 낭자 가 쓴 것 입 니 다.
Class Cls_Cache
Rem ================== ====================
Rem = , : 。 , 。 。
Rem = :
Rem = :Reloadtime ( ) 14400
Rem = MaxCount , 。 300
Rem = CacheName , "Dvbbs", , 。
Rem = :Name , 。
Rem = :value 。
Rem = :ObjIsEmpty() 。
Rem = :DelCahe(MyCaheName) , 。
Rem ========================
Public Reloadtime,MaxCount,CacheName
Private LocalCacheName,CacheData,DelCount
Private Sub Class_Initialize()
Reloadtime=14400
CacheName="Dvbbs"
End Sub
Private Sub SetCache(SetName,NewValue)
Application.Lock
Application(SetName) = NewValue
Application.unLock
End Sub
Private Sub makeEmpty(SetName)
Application.Lock
Application(SetName) = Empty
Application.unLock
End Sub
Public Property Let Name(ByVal vNewValue)
LocalCacheName=LCase(vNewValue)
End Property
Public Property Let Value(ByVal vNewValue)
If LocalCacheName<>"" Then
CacheData=Application(CacheName&"_"&LocalCacheName)
If IsArray(CacheData) Then
CacheData(0)=vNewValue
CacheData(1)=Now()
Else
ReDim CacheData(2)
CacheData(0)=vNewValue
CacheData(1)=Now()
End If
SetCache CacheName&"_"&LocalCacheName,CacheData
Else
Err.Raise vbObjectError + 1, "DvbbsCacheServer", " please change the CacheName."
End If
End Property
Public Property Get Value()
If LocalCacheName<>"" Then
CacheData=Application(CacheName&"_"&LocalCacheName)
If IsArray(CacheData) Then
Value=CacheData(0)
Else
Err.Raise vbObjectError + 1, "DvbbsCacheServer", " The CacheData Is Empty."
End If
Else
Err.Raise vbObjectError + 1, "DvbbsCacheServer", " please change the CacheName."
End If
End Property
Public Function ObjIsEmpty()
ObjIsEmpty=True
CacheData=Application(CacheName&"_"&LocalCacheName)
If Not IsArray(CacheData) Then Exit Function
If Not IsDate(CacheData(1)) Then Exit Function
If DateDiff("s",CDate(CacheData(1)),Now()) < 60*Reloadtime Then
ObjIsEmpty=False
End If
End Function
Public Sub DelCahe(MyCaheName)
makeEmpty(CacheName&"_"&MyCaheName)
End Sub
End Class
Set WydCache=New Cls_Cache
WydCache.Reloadtime=0.5 ' ( )
WydCache.CacheName="pages" '
IF WydCache.ObjIsEmpty() Then '' ( , )
Response.write WydCache.Value
Else
..................
BoardJumpList=xxx
WydCache.Value=BoardJumpList '
Response.write BoardJumpList
End if
mycache.DelCahe(" ")
slightboy 썼어 '========================
'clsCache.asp
'========================
'== begin : 2004-6-26 21:51:47
'== copyright : slightboy (C)1998-2004
'== email : [email protected]
'========================
'========================
' Dim Application(2)
' Application(0) Counter
' Application(1) dateTime
' Application(2) Content
Public PREFIX
Public PREFIX_LENGTH
Private Sub Class_Initialize()
PREFIX = "Cached:"
PREFIX_LENGTH = 7
End Sub
Private Sub Class_Terminate
End Sub
'
Public Property Let Cache(ByRef Key, ByRef Content)
Dim Item(2)
Item(0) = 0
Item(1) = Now()
IF (IsObject(Content)) Then
Set Item(2) = Content
Else
Item(2) = Content
End IF
Application.Unlock
Application(PREFIX & Key) = Item
Application.Lock
End Property
' ++
Public Property Get Cache(ByRef Key)
Dim Item
Item = Application(PREFIX & Key)
IF (IsArray(Item)) Then
IF (IsObject(Item)) Then
Set Cache = Item(2)
Else
Cache = Item(2)
End IF
Application(PREFIX & Key)(0) = Application(PREFIX & Key)(0) + 1
Else
Cache = Empty
End IF
End Property
'
Public Property Get Exists(ByRef Key)
Dim Item
Item = Application(PREFIX & Key)
IF (IsArray(Item)) Then
Exists = True
Else
Exists = False
End IF
End Property
'
Public Property Get Counter(ByRef Key)
Dim Item
Item = Application(PREFIX & Key)
IF (IsArray(Item)) Then
Counter = Item(0)
End IF
End Property
'
Public Property Let dateTime(ByRef Key, ByRef SetdateTime)
Dim Item
Item = Application(PREFIX & Key)
IF (IsArray(Item)) Then
Item(1) = SetdateTime
End IF
End Property
'
Public Property Get dateTime(ByRef Key)
Dim Item
Item = Application(PREFIX & Key)
IF (IsArray(Item)) Then
dateTime = Item(1)
End IF
End Property
'
Public Sub ResetCounter()
Dim Key
Dim Item
Application.Unlock
For Each Key in Application.Contents
IF (Left(Key, PREFIX_LENGTH) = PREFIX) Then
Item = Application(Key)
Item(0) = 0
Application(Key) = Item
End IF
Next
Application.Lock
End Sub
'
Public Sub Clear(ByRef Key)
Application.Contents.Remove(PREFIX & Key)
End Sub
'
Public Sub ClearUnused()
Dim Key, Keys, KeyLength, KeyIndex
For Each Key in Application.Contents
IF (Left(Key, PREFIX_LENGTH) = PREFIX) Then
IF (Application(Key)(0) = 0) Then
Keys = Keys & VBNewLine & Key
End IF
End IF
Next
Keys = Split(Keys, VBNewLine)
KeyLength = UBound(Keys)
Application.Unlock
For KeyIndex = 1 To KeyLength
Application.Contents.Remove(Keys(KeyIndex))
Next
Application.Lock
End Sub
'
Public Sub ClearAll()
Dim Key, Keys, KeyLength, KeyIndex
For Each Key in Application.Contents
IF (Left(Key, PREFIX_LENGTH) = PREFIX) Then
Keys = Keys & VBNewLine & Key
End IF
Next
Keys = Split(Keys, VBNewLine)
KeyLength = UBound(Keys)
Application.Unlock
For KeyIndex = 1 To KeyLength
Application.Contents.Remove(Keys(KeyIndex))
Next
Application.Lock
End Sub
End Class
slightboyn Set Wyd=New JayCache
Wyd.dateTime("Page")=
If Wyd.Exists("Page") Then
Response.write Wyd.Cache("Page") '
Else
Wyd.Cache("Page")=xxx
Responxe.write xxx
End IF
Wyd.Clear("page")'