Sam Farmer

Growing up I never imagined I would play bass guitar for the Dave Matthews Band. And indeed it never happened.

But I have become passionate about making software.

Sharing Data Across Instances with objectSave() and objectLoad()

December 3, 2010

Running multiple ColdFusion instances is pretty awesome from failover to performance. Sharing data among them throws up a couple possibilities:

Recently I needed to do just this with a dataset of structures and arrays that could have changed at anytime. This made option 1 a little tricky. Option 2 was my favorite but required some extra installs with Ehcache (which is a simple 7 step process, but would have required testing, yada, yada). So, option 3 was what we picked and it worked well.

Here is a simple example of how to do it. First create and save your object:

myObject = { funRun = [1,3,5], hardcore = [10,26,1000] }; objectSave( myObject, "myObject.cfo");

The objectSave() function takes two arguments; first the object, and second the filename. By default it saves it relatively to the running file. The documentation use a ".out" extension but I think a ".cfo" is more fun (ColdFusion Object or if you need to please your CFO tell them you named it after them!).

Retrieval is just as easy:

And that will work across any instance.

If you have large objects you may run into issues with writes and saves coming at the same time. In that case wrap the objectLoad() in a try/catch.


No Comments

Some comments have been lost over the years due to moving hosts.

More


More blog entries that I have written.

Code coloring by PRISM.