As Transfer intelligently handles object caching and destroying as memory
changes this is probably better for your system than just throwing objects
into Session without any memory management. I was originally concerned about
putting too many rich objects into session in case it impacted on memory
usage and overall system stability.
Yes. It's very, very bad to put Transfer objects in session scope if
Transfer is also caching them. This has cropped up in discussion on
this list a few times.
> I'm tangentially wondering if this might reduce the memory footprint
> of my app which has been wedging itself every few hours since
> launching Saturday (although is running suspiciously ok this morning).
Update to the very latest Transfer from SVN. Mark has made a number of
improvements over the last week as Broadchoice has been load testing
and analyzing our Transfer-based app (or rather, the excellent folks
at Alagad have been doing this for us).
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
Once things start to settle with the load testing at Broadchoice, I'll
do a RC 2 release of the Transfer 1.0 for people to play with.
Mark
I have the same issue, but I addressed it by creating a CurrentUser
object of my own, which I do store in the session scope. The
CurrentUser keeps a record of the UserId for the Transfer based User
TO in its instance data and whenever I need something from the
Transfer based User TO I get it via a Transfer.get() inside
CurrentUser. There may be issues with this design decision, which
I'd be happy to hear about, but it definitely works.
Bob
Are you saying you add information to the User object but don't commit
it? That sounds like a poor design to me. Transfer objects are meant
to be persistent objects - if you modify the User object in memory, it
will affect *all* uses of that object (by other threads) since there
is only one cached object (by default). If I understand correctly what
you're doing, you're just setting yourself up for data corruption and
all sorts of hard-to-debug problems.
> To be honest, I'm still not
> clear at all on how a session-scoped TO could fall out of cache
> anyway...isn't the fact that it is in the session scope creating a
> continuous strong reference to that object? Is this some kind of bug in CF's
> session handling?
How would Transfer know where you stored the reference? If Transfer
needs to reap its cache and that User object is a candidates based on
its usage pattern, out it goes. Your session scope reference is
completely independent of what Transfer knows about.
That's a very reasonable approach.
My favored approach is to have a UserService that has a
getCurrentUser() method that returns
transfer.get("user.user",session.userid) but there are lots of ways to
handle this without risking data corruption...
Are you saying you add information to the User object but don't commit
it? That sounds like a poor design to me. Transfer objects are meant
to be persistent objects - if you modify the User object in memory, it
will affect *all* uses of that object (by other threads) since there
is only one cached object (by default). If I understand correctly what
you're doing, you're just setting yourself up for data corruption and
all sorts of hard-to-debug problems.
> To be honest, I'm still not> clear at all on how a session-scoped TO could fall out of cacheHow would Transfer know where you stored the reference? If Transfer
> anyway...isn't the fact that it is in the session scope creating a
> continuous strong reference to that object? Is this some kind of bug in CF's
> session handling?
needs to reap its cache and that User object is a candidates based on
its usage pattern, out it goes. Your session scope reference is
completely independent of what Transfer knows about.
That's a good thing to be doing in general regardless, it doesn't have
much to do with specifically storing things in session scope.
>
> Transfer doesn't know where I've stored the reference, but the JVM clearly
> must know that the object has an active reference. And as I understand it,
> the soft reference handler should not be discarding anything that has an
> active reference to it, but this may be where I'm mistaken. I thought only
> objects that were candidates for garbage collection would be eligable for
> reaping. Is this not the case?
It depends on your cache config. If you have a maxobjects or timeout,
it could definitely fall out of the cache.
That being said, I have heard about (weird) cases were objects have
fallen out of the cache, when it was just a SoftReference
configuration.
Mind you - YMMV. At the end of the day, if you're not experiencing
any issues, and everything is working as you expected, then do as you
will.
Mark