Instantiating the object into the session scope is fine. However,
manipulating the session scope from inside the CFC as per:

<!--- query is loaded to session scope --->
<cfset session.qryAllProducts = qryAllProducts>
<cfreturn session.qryAllProducts>

is not recommended. This breaks the encapsulation rules usually
associated with CFCs.

Consider doing this instead: Create a method that queries the DB and
saves the query in a property in the VARIABLES scope. Then have the
"getter" method return the VARIABLES scoped query. This has the
benefit of keeping the query data in the component instead of having
to save it separately in the session scope and makes the thing behave
like an object with its own properties.

It's when the object has these properties that locking can become more
important. One technique that works well for instantiated objects is
to use a named lock where a UUID forms the name. Create the UUID as
part of the init() method and use it for every lock in the component:

<cfset VARIABLES.MyLockName = createUUID()>
.....
<cflock name="#VARIABLES.MyLockName #" .....

This means that every instance of the component gets a unique lock
name, improving performance over full scope locks or a single shared
name.

On 10/31/05, Michel Deloux <[EMAIL PROTECTED]> wrote:
> Hi all
>
> I'm looking for comments about cfc instantiation and the best
> practices for cflock.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:222689
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=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to