BA Space Cache class code
Copy Code code as follows:
<%
Class Cache
Private obj ' cache content
Private Expiretime ' Expiration time
Private Expiretimename ' Expired time application name
Private CacheName ' cache content application name
Private path ' URL
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
' Is empty
If IsEmpty (obj) Then
Blempty=true
Else
Blempty=false
End If
End Property
Public Property Get Valid
' is available (expired)
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)
' Set cache name
CACHENAME=STR & Path
Obj=application (CacheName)
EXPIRETIMENAME=STR & "Expires" & Path
Expiretime=application (Expiretimename)
End Property
Public Property Let expires (tm)
' Reset Expiration Time
Expiretime=tm
Application.Lock
Application (Expiretimename) =expiretime
Application.UnLock
End Property
Public Sub Add (Var,expire)
' Assign value
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
' Take 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 ()
' Release application
Application.Lock
Application (CacheName) =empty
Application (Expiretimename) =empty
Application.UnLock
Obj=empty
Expiretime=empty
End Sub
Public function equal (VAR2)
' Comparison
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
%>
How to use:
Copy Code code as follows:
set mycache=new cache
mycache.name= "Flash1"
if mycache.valid then
startget =
mycache . Value
else
startget = gethttppage (httpurl)
Mycache .add
startget , DateAdd ("H", 3,now)
End if
list=getbody (
startget , "</form>", " <!-- ******** The middle of the page code end ******** --> ", False,false)