2 Replies Latest reply on Dec 4, 2006 1:00 PM by a.s.webster

    refresh cached queries on multiple servers

    a.s.webster Level 1
      We have numerous cached queries for a cfmx 7 application. Our production environment consisits of multiple servers in a load balanced set up. We want to have one link to refresh all of the cached queries on each server. This works fine on one server as the cfm we are calling loops through the directory of queries and resets the timeout to 0 and performs a query so each one gets refreshed. When I try to run it in production and use cfhttp to call each page and refresh the queies, they do not refresh. Any ideas?

        • 1. Re: refresh cached queries on multiple servers
          monkey_woo_too Level 1
          Calling application specific code on clustered sites can be a bit of a pain.. here's how i do it.

          2. Create a folder on your webroot called '_cluster' e.g 'c:\htdocs\_cluster'

          1. Change the mappings in your C:\JRun4\servers\cfusion\cfusion-ear\cfusion-war\WEB-INF\jrun-web.xml so that there is a mapping to '_cluster'.
          I did it like this:
          <virtual-mapping>
          <resource-path>/_cluster</resource-path>
          <system-path>C:\htdocs\_cluster</system-path>
          </virtual-mapping>

          2. In your application.cfc onApplicationStart add a reference to the object to the application like this:
          application.oApplication = this;

          3. Create a method in your application.cfc that can clear all the queries like this:
          <cffunction name="clearCache">
          <cfobjectcache action="clear">
          </cffunction>

          4. on your site, create page that can call that method on your application (/_cluster/clearQueries.cfm) like this:

          variables.appScopeTacker = createObject("java", "coldfusion.runtime.ApplicationScopeTracker");
          variables.stApplication = variables.appScopeTacker.getApplicationScope(url.sAppName);
          variables.stApplication.oApplication.clearCache();

          sAppName you can hardcode if you like.

          5. Create another file on your server that can call this first file on all the instances (/_cluster/clearClusterQueries.cfm)
          //get all the cf instances that are in your cluster
          <cfscript>
          variables.aServerNames[1] = "192.168.1.1:8300";
          variables.aServerNames[2] = "192.168.1.2:8300";
          variables.aServerNames[3] = "192.168.1.3:8300";
          //etc.
          </cfscript>
          //loop them and call the clearQueries template on each one
          <cfloop from="1" to="arrayLen(variables.aServerNames)" index="variables.iServerName">
          <cfscript>
          variables.sServerName = variables.aServerNames[variables.iServerName];
          //this is why you need a mapping to your site in
          variables.sURL = " http://#variables.sServerName#/_cluster/clearQueries.cfm";
          </cfscript>
          <cfhttp url="#variables.sURL#"/>
          <!--- if you like you can put an iframe in here so you can see what happens
          <iframe src="#variables.sURL#"></iframe>
          --->
          </cfloop>

          6. call http://x.x.x.x:8300/_cluster/clearClusterQueries.cfm on any server.

          Obviously, you can use a set up that allows you to inspect applications running on all your instances and determine what functions are available
          on them so that you can call any application.cfc function on any instance, but for brevities sake i've kinda hardcoded this solution for you.
          • 2. Re: refresh cached queries on multiple servers
            a.s.webster Level 1
            Thanks!

            I had to modify it a bit as the clearCache() method of the java object was said not to exist.

            calling structClear(variables.stApplication); worked fine though.

            and calling <cfobjectcache action="clear"> was a lot simpler to clear queries than looping through each one and refreshing it.