Search

Friday, September 07, 2007

Howto Reload Model-Glue Applications

There are a few different way to reload a Model-Glue application. Before you start, please Note the "reloadKey" and "reloadPassword" in your ColdSpring.xml file. If the "reload" value is set to true in your ColdSpring.xml file, you do not need to do anything as the application is reloaded every time you load/refresh the page. While this can be helpful for development, it will kill your application in production, so beware. If the "reload" value is set to false, here is how to reload your application: If you want your application to reload on every request: 1. Edit the ColdSpring.xml file and set the "reload" value to true 2. Invoke the application by going to "http://yourhost/yourapplication/?init=true", where "init" is the value of the "reloadKey" and "true" is the value of the "reloadPassword" If you don't want the application to reload on every request: 1. Invoke the application by going to "http://yourhost/yourapplication/?init=true", where "init" is the value of the "reloadKey" and "true" is the value of the "reloadPassword" The alternative solution I use while always leaving the reload key to "false" is to write your own re-init method. For some reason I find that invoking the application with "http://yourhost/yourapplication/?init=true" is a pain and I'm not sure that it clears application or session scope variables. So instead, I have my own method. In your "application.cfc", create the onRequestStart function as follows. If it already exists, just add the code shown here.
<cffunction name="OnRequestStart" output="no">
  <cfif structKeyExists(url, "init")>
    <cfset structclear(Application) />
    <cfset structclear(Session) />

    <cfset onApplicationStart() />
  </cfif>
</cffunction>
Now, when you invoke the url "http://yourhost/yourapplication/?init", your application will re-init by deleting the application and session scopes. The concept is based on some code I say Ray Camden use. Maybe it's reinventing the wheel and ColdSpring already does that but I'm not sure.
// //]]>