On Apr 4, 2005 10:12 AM, Cliff Meyers <[EMAIL PROTECTED]> wrote:
(1) Use the variables scope for instance variables to prevent access from
outside the object, and
(2) Use the function local scope ("var") to make sure that the objects are
thread safe.

Yup, those are good.

Is the general rule that if something isn't part of my object's
instance data (ie, stored in the variables scope) that EVERYTHING else be
stored in function local scope?

The lifetime of 'var' scope is just the execution of a particular function. The lifetime of 'variables' scope is the lifetime of the CFC instance itself, i.e., whatever scope you store that instance in (e.g., page scope, session scope, application scope). If you make multiple calls to the same CFC instance, the data stored in 'variables' scope will be present for each call.

Can someone explain what kinds of
problems emergy if I were - for example - to do a cfquery inside one of my
methods using a name attribute hadn't already been created as a function
local scoped variable?

If the CFC instance is stored in a shared scope and multiple requests (users) caused that function to execute at the same time, then the query result could be overwritten by one thread while another thread is using it. If you don't 'var' scope your query result, it ends up in 'variables' scope.

So, you can deduce from that, using 'variables' scope means you need to think about thread safety issues. That's why, in general, CFC instances cached in application scope should be stateless (have no 'variables' scope data except for internal caches) and any stateful CFCs (that have important 'variables' scope data) are created as-needed for each request or stored in session scope (although you still need to consider multiple threads caused by a single user - frames or repeat submits, for example).

Also, are there any concerns/requirements for locking method calls when an
object is stored in a persistent scope?

You mean a shared scope. Scopes aren't persistent. Databases are persistent.

Yes, you need to consider thread safety when using objects stored in shared scopes which means you might need to lock for certain method calls.
--
Sean A Corfield -- http://corfield.org/
Team Fusebox -- http://fusebox.org/
Got Gmail? -- I have 50, yes 50, invites to give away!

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood ----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).

An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]

Reply via email to