Troy,

>structInsert(application,"sessions",newStruct());
>structInsert(application.sessions,session.sessionid,structNew());
>structInsert(application.sessions[session.sessionid],"userid","mrFusion");
>structInsert(application.sessions[session.sessionid],"created",now());
>structInsert(application.sessions[session.sessionid],"accessed",now());
>
>So I end up with a structure that looks like this:
>application.session.e430715398cb325a314b.userid = mrFusion
>application.session.e430715398cb325a314b.created = {ts '2006-03-30
>16:54:59'}
>application.session.e430715398cb325a314b.accessed = {ts '2006-03-30
>16:54:59'}
>
>Then every time a user requests a page, the accessed value gets
>updated with a new time stamp like this:
>
>application.session.e430715398cb325a314b.accessed = now();
>
>When one of these values is updated, do I have to lock the application
>scope or can I just lock the area that I want to change.  Or do I have
>to lock anything at all.
>
>I wanted to keep this information in application scope so that I can
>monitor the sessions of the application.

The only place you could run into a race condition would be if you have a
process for deleting expired sessions. If that code was in the middle of
deleting a session and you tried to read in a different thread, you could
potentially run into a race condition.

Also, if you want to avoid locking the entire scope, you can always use a
named lock. I usually use a name that reflects the variable being updated.
This allows you to update a single branch of a scope w/out locking the whole
thing.

You could use a named lock like:

<cflock name="AppSession#SessionId#" timeout="30" type="exclusive">
        -- read/write safe --
</cflock>

(Make sure SessionId is thread safe.)

Something like this would allow you to lock the code just for that
user--without locking the entire application scope.

-Dan


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:236632
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to