asp缓存类(5)
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")'删除缓存