| Contents > Developing ColdFusion MX Applications > Building and Using ColdFusion Components > Building ColdFusion components > Structuring and reusing code Using CFCs in persistent scopes |
|
|
|
|
||
You can put a CFC instance in the Session or Application scope. This way, the component properties continue to exist while the scope persists,. For example, you might want to use a CFC for a shopping cart application, where the shopping cart contents must persist for the length of the user's session. If you put the shopping cart CFC in the Session scope, you can use component properties to store the cart contents. For example, the following line creates an instance of the shoppingCart component in the Session scope.
<cfobject name="Session.myShoppingCart" component="shoppingCart">
Code that manipulates persistent scope CFC properties must be locked, just as all other code that manipulates persistent scope properties must be locked. Therefore, you must lock both of the following types of application code:
If you put multiple CFC instances in a single persistent scope, you can create a named lock for each CFC instance. For more information on locking, see Using Persistent Data and Locking.
Note: Session scope CFCs cannot be serialized, so you cannot use them with clustered sessions; for example, if you want to support session failover among servers.
For an example of an application that uses a component in a persistent scope, see the CFML/HTML PetMarket application, available from the Macromedia Pet Market Blueprint Application page, www.macromedia.com/devnet/blueprint/. The Session scope user CFC has properties with information about the user, such as name, telephone number, e-mail address, and billing and shipping addresses. The CFC also includes methods for managing the user: a login method, a method that populates the object's properties from a database, and so on.
|
|
||
| Contents > Developing ColdFusion MX Applications > Building and Using ColdFusion Components > Building ColdFusion components > Structuring and reusing code Using CFCs in persistent scopes |
|
|
ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting
Version 6.1
Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/buildi54.htm