Then encapsulate other operations, such as cookies, sessions, and application
CookieState class:
<%
Class CookieState Private CurrentKey Public Default Property Get Contents(ByVal Value)
Contents = Values(Value)
End Property Public Property Let Expires(ByVal Value)
(CurrentKey).Expires = DateAdd("d", Value, Now)
End Property
Public Property Get Expires()
Expires = (CurrentKey).Expires
End Property Public Property Let Path(ByVal Value)
(CurrentKey).Path = Value
End Property
Public Property Get Path()
Path = (CurrentKey).Path
End Property Public Property Let Domain(ByVal Value)
(CurrentKey).Domain = Value
End Property
Public Property Get Domain()
Domain = (CurrentKey).Domain
End Property Public Sub Add(ByVal Key, ByVal Value, ByVal Options)
(Key) = Value
CurrentKey = Key
If Not (IsNull(Options) Or IsEmpty(Options) Or Options = "") Then
If IsArray(Options) Then
Dim l : l = UBound(Options)
Expire = Options(0)
If l = 1 Then Path = Options(1)
If l = 2 Then Domain = Options(2)
Else
Expire = Options
End If
End If
End Sub Public Sub Remove(ByVal Key)
CurrentKey = Key
Expires = -1000
End Sub Public Sub RemoveAll()
Clear()
End Sub Public Sub Clear()
Dim iCookie
For Each iCookie In
(iCookie).Expires = FormatDateTime(Now)
Next
End Sub Public Function Values(ByVal Key)
Values = (Key)
End Function
Private Sub Class_initialize()
End Sub
Private Sub Class_Terminate()
End Sub End Class
%>
SessionState class:
<%
Class SessionState Public Default Property Get Contents(ByVal Key)
Contents = Session(Key)
End Property Public Property Let TimeOut(ByVal Value)
= Value
End Property Public Property Get TimeOut()
TimeOut =
End Property Public Sub Add(ByVal Key, ByVal Value)
Session(Key) = Value
End Sub Public Sub Remove(ByVal Key)
(Key)
End Sub Public Function Values(ByVal Key)
Values = Session(Key)
End Function Public Sub Clear()
()
End Sub Public Sub RemoveAll()
Clear()
End Sub
Private Sub Class_initialize()
End Sub
Private Sub Class_Terminate()
End Sub End Class
%> The Application class is encapsulated into the CacheState class:
<%
Class CacheState Private IExpires Public Default Property Get Contents(ByVal Value)
Contents = Values(Value)
End Property Public Property Let Expires(ByVal Value)
IExpires = DateAdd("d", Value, Now)
End Property
Public Property Get Expires()
Expires = IExpires
End Property Public Sub Lock()
()
End Sub Public Sub UnLock()
()
End Sub Public Sub Add(ByVal Key, ByVal Value, ByVal Expire)
Expires = Expire
Lock
Application(Key) = Value
Application(Key & "Expires") = Expires
UnLock
End Sub Public Sub Remove(ByVal Key)
Lock
(Key)
(Key & "Expires")
UnLock
End Sub Public Sub RemoveAll()
Clear()
End Sub Public Sub Clear()
()
End Sub Public Function Values(ByVal Key)
Dim Expire : Expire = Application(Key & "Expires")
If IsNull(Expire) Or IsEmpty(Expire) Then
Values = ""
Else
If IsDate(Expire) And CDate(Expire) > Now Then
Values = Application(Key)
Else
Call Remove(Key)
Value = ""
End If
End If
End Function Public Function Compare(ByVal Key1, ByVal Key2)
Dim Cache1 : Cache1 = Values(Key1)
Dim Cache2 : Cache2 = Values(Key2)
If TypeName(Cache1) <> TypeName(Cache2) Then
Compare = True
Else
If TypeName(Cache1)="Object" Then
Compare = (Cache1 Is Cache2)
Else
If TypeName(Cache1) = "Variant()" Then
Compare = (Join(Cache1, "^") = Join(Cache2, "^"))
Else
Compare = (Cache1 = Cache2)
End If
End If
End If
End Function
Private Sub Class_initialize()
End Sub
Private Sub Class_Terminate()
End Sub End Class
%>
The above three classes can be instantiated using the class name after removing State, for example
Dim Cookie : Set Cookie = New CookieState
Dim Session : Set Session = New SessionState
Dim Cache : Set Cache = New CacheState
Previous page123Next pageRead the full text