On 8/15/06, Russ <[EMAIL PROTECTED]> wrote:
> Dave,
>
> How exactly does this help in clustered environments? Where do you store
> the beans and how do you do snapshots?
>
Well, lots of people use CFCs to, among other things, store
information in the session scope. Let's use the classic example of a
User class that's responsible for remembering information about the
currently logged-in user. If you're using a single CF instance, you
can simply use something like this to create the CFC in the session
scope:
<cfset session.userObject = createObject("component",
"path.to.my.User").init() />
However, CFCs are not serializable in CFMX (any version), which means
that if you have session replication turned on (which is the machinery
that passes the session data around to all CFMX instances in the
cluster), you'll actually get an error when trying to use the above
code and then trying to reference session.userObject in your code.
(Some might chime in that you can turn on sticky sessions, which will
pin you to one box, but this defeats the purpose of replication, in my
opinion, as you're tying the user to one location and lose
scalability.) Essentially: you can't put CFCs in the session scope if
you run a clustered setup.
OK, now that the problem statement is clear, how do we work around
this? Well, it's important to realize that *only* CFCs have this
problem. All other complex datatypes such as arrays, structs
(including nested datatypes, such as struct of arrays, etc.) replicate
without issue. So what I've done in my code is captured a snapshot of
the instance data (sometimes referred to as the Memento design
pattern) at the end of each page, and then stored the instance data in
the session scope (i.e, session.userMemento =
userObject.getInstanceData() ). Then, on the next page that I need
this data, I simply create a local variable for the User class, but
pass in the session-scoped instance data (session.userMemento), which
is "smart" enough accept the structure and set it up as my new
instance's instance variables. I gain the ability to keep users
separate.
I've been meaning the blog my setup for a while, and this is a good
motivation to get it done. I'll post how the CFC is "smart" enough to
use the session-scoped snapshot and, hopefully, provide a bit more
clarity to this post.
Stay tuned (if you're still interested!),
Regards,
Dave.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four
times a year.
http://www.fusionauthority.com/quarterly
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:249886
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4