Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Could not find object method in ColdFusion...

Posted on 2012-03-29
8
Medium Priority
?
300 Views
Last Modified: 2012-03-29
Hi,

I have an instance of a ColdFusion object created and stored in session scope the first time during user's session start and persists over the lifespan of the session (See code below). The problem is that every time I introduce a new method to the component and deploy the method to Production, my users are receiving the error "Could not find method 'getProductInfo'..." This is because the users' session still persists and therefore all the methods and properties of the object are still referring to instance of object in the session that was created right before code deployment.

<cfparam name="session.myObject" default="#createObject('component','myComponents.Products').init(request.someVariable)#">
<cfset variables.result = session.myObject.getProductInfo(request.CustomerID)>

How do I prevent/resolve this problem?

NOTE: I could have used local variable to store the object, but I don't want to do that because doing so would require the object to be created on every page load. And I don't want to store the object in application variable neither as it presents other problems.

I'm using CF 8.

Many thanks in advance.
0
Comment
Question by:WebAppDeveloper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 39

Expert Comment

by:gdemaria
ID: 37783849
Typically, I do this in the application scope, which is much easier to rebuild on demand.   You just add a secret URL variable such as  &reloadAppVars=1 and that is tested in the application.cfc file and forces the reload.

In your case, you really can't do this as you have many session variables already loaded.  The user must logout and log back in.  Which basically means you have to do you loads to production at night and kick out all users when you do it forcing the session variables to refresh.   You can do that by changing the application name a little such as "myApp" to "MyApp1"  or restarting the CF service.
0
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 1200 total points
ID: 37783900
Using the application scope is probably the best best.. but you said that's not an option.  

If you think it'll happen on a regular basis, you could add a time stamp flag to both the application and session scope. The stamp would indicate the date the components were last updated.

   OnApplicationStart
         application.ComponentsLastChanged = (date and time code last updated);

   OnSessionStart
        session.ComponentsLastChanged = now();

Then compare the dates in OnRequestStart. If the application timestamp is later than the one in the session scope, run some function to reinitialize the session objects

   OnRequestStart:
      <cfif dateCompare(application.ComponentsLastChanged, session.ComponentsLastChanged) gt 0>
               <cfset methodToReinitializeSessionComponents()>
       </cfif>
0
 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 800 total points
ID: 37783911
actually, you could just add a statement..

   <cfset structDelete(session, myObject)>

Leave that in there for 30 minutes and then remove it..

For the 30 minutes, you'll reload the object on every page load, but at least you're sure you'll have all your users reloaded.   Assuming that the session timeout is less than 30 minutes...
0
Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

 
LVL 52

Expert Comment

by:_agx_
ID: 37783948
Oops.. mid-air post collision.

I think my suggestion would work too. But if it's anything more than a single component, I'd probably go with gd's suggestion of a complete reset.  Starting with a clean slate is almost always less problematic. If only because it's easy forget dependencies and end up causing problems because you forget to reload X when you reloaded Y.
0
 
LVL 39

Accepted Solution

by:
gdemaria earned 800 total points
ID: 37783953
agx, I like the general idea, not sure I'm following the date stamps though.  The application and session scopes aren't firing in the situations when the error occurs.   They fire on a new user connection, that's not the problem, right?

So an existing user, who is already connected with a session loaded can't find the newly loaded cfc method.   So, I think the load date should compare against a hard coded, "cfc last uploaded date"

something like this perhaps...


onSessionStart
      session.ComponentsLastLoaded = now();


   OnRequestStart:
      <cfset request.componentsUpgradDate = "3/12/2012"> <!---- change this each time you upload a new CFC

      <cfif dateCompare(session.ComponentsLastLoaded, request.componentsUpgradDate) gt 0>
               <cfset methodToReinitializeSessionComponents()>
       </cfif>
0
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 1200 total points
ID: 37783991
No, I think we're thinking the same thing.  I was assuming they'd automatically call onApplicationStart to reset the application (that's what I do with updates to make sure all changes propogate). In which case it doesn't matter whether you store the app time stamp in the application scope OR hard code it in OnRequestStart. Either way you have to change the Application.cfc file - but the net effect should be the same.

Either is fine, but you're right, hard coding the date in OnRequestStart is simpler.
0
 

Author Comment

by:WebAppDeveloper
ID: 37784385
gdemaria,

Should it be this way instead?

 <cfif dateCompare(request.componentsUpgradDate, session.ComponentsLastLoaded) gt 0>
         <cfset methodToReinitializeSessionComponents()>
 </cfif>

Meanting if request.componentsUpgradDate is later than session.ComponentsLastLoaded, then we re-init the session. Otherwise, the code will be reinitializing the session on every page load after user's session times out and begins a new session?
0
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 1200 total points
ID: 37784448
Yes, I'm guessing gd just swapped the dates in my original example accidentally.
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question