This content has been marked as final. Show 2 replies
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:
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:
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);
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
variables.aServerNames = "192.168.1.1:8300";
variables.aServerNames = "192.168.1.2:8300";
variables.aServerNames = "192.168.1.3:8300";
//loop them and call the clearQueries template on each one
<cfloop from="1" to="arrayLen(variables.aServerNames)" index="variables.iServerName">
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";
<!--- if you like you can put an iframe in here so you can see what happens
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.
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.