
How to caching the vb object in application scope
Hi everyone,
Because for i really need caching the user object in application variable, when i
login my web application and add it to my application scope and later i can use
it check its access control rights, it is important to me.
I also know that set the Non-Agile component in application is not advisability,
So i make a ADO recordsets in Application scope to store my user obj like this:
Sub Application_OnStart
' ========================================================================
Set rsUser = Server.CreateObject("ADODB.Recordset")
rsUser.CursorLocation = 3 'adUseClient
rsUser.Fields.Append "ID", 200,50,adFldMayBeNull
rsUser.Fields.Append "user_obj", 12,,adFldMayBeNull
rsUser.Open
set Application("user_obj") = rsUser
' ========================================================================
End Sub
and use this in my login process asp file like this:
' ========================================================================
Dim uobj
set uobj = Server.CreateObject("AccessControl.User")
Application("user_obj").MoveFirst
Application("user_obj").Find "ID='" & uid & ":" & sid & "'"
if Application("user_obj").Eof Then
err.Clear
uobj.UserID = cstr(uid)
uobj.SchoolID = cstr(sid)
uobj.Populate
Call CheckSystemError(err)
Application.Lock
Application("user_obj").AddNew
Application("user_obj").Fields("ID").Value = uid & ":" &
sid
Application("user_obj").Fields("user_obj").Value = uobj
Application("user_obj").Update
Application.UnLock
End if
set uobj = Application("user_obj").Fields("user_obj").Value
' ========================================================================
then i can use my user obj is every module in this way instead of populate from
database when i need it.
my user object is a apartment-threaded(not FTM), But my ado recordset object is a
Free-threaded and also a disconnected recordset. i think it is agile component.
I do not sure this way can have serious pitfalls, Because if my component caches
interface pointers, those pointers must themselves be agile, or must be stroed in
the COM Global Interface Table, otherwiase worse effect performance.
I still want to look some good ideal how to serialization a object property to a
xml string or other variable to store my object.
Any ideal will be appreciate!
Thanx,
Liu Yuan