ColdFusion Zeus POTW: Application Metadata

This post is more than 2 years old.

Time for another quick ColdFusion Zeus preview. This one will probably be of lesser value to some folks, but it addresses an issue I've been raising for years, and that is:

If ColdFusion knows something, I should know it.

Simple enough concept, right? However, it's not been easy to discover simple, trivial things about your environment unless you were willing to hack around it. Here's an incredibly trivial example: Session Management. How would you know if sessions were enabled for the current request? Currently you can't unless you try to set or read a Session variable and wrap the call with a try and catch. I love ColdFusion, but I have no qualms about calling that stupid.

ColdFusion Zeus addresses this by exposing a new function, getApplicationMetaData, that returns settings about the current application. To be clear, it does not return application variables. Remember that the Application scope is a structure you can introspect easily enough. Instead, getApplicationMetaData will return current settings for the active application. Here's a quick example (and I snuck in a few things here too that are new):

component { this.name="moo"; this.sessionManagement="true"; this.datasource="cfartgallery";

this.mappings = {
			"/foo":expandPath("./")
				};

this.customtagpaths=expandPath("./");

this.sessioncookies.httpOnly = true;

this.invokeImplicitAccessor = true;

this.inmemoryfilesystem.enabled = true;
this.inmemoryfilesystem.size = 10;

}

And then here is my test template:

<cfdump var="#getApplicationMetaData()#" label="get Application Metadata">

And the result:

So - how useful is this? Probably not very. Those of us working with open source libraries or those who ship packaged solutions though can really make good use of this. And darnit - ColdFusion knows this info, so should we!

p.s. If you look at the Application.cfc file above, you may notice a few new things. I'm not going to talk about all of them, but I will address one:

this.inmemoryfilesystem.enabled = true; this.inmemoryfilesystem.size = 10;

In ColdFusion Zeus, you can now use the VFS on a per Application basis. That means an Application can use a vfs folder like ram://info and not worry about another application using the same folder. Your virtual files and folders are 100% black boxes into your Application-memory space. You can also configure your own size too. Nice.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Tony Nelson posted on 12/5/2011 at 7:20 PM

So is getApplicationMetaData() basically the documented version of application.getApplicationSettings()?

Comment 2 by Raymond Camden posted on 12/5/2011 at 7:22 PM

And supported. ;)

Comment 3 by Will B. posted on 12/5/2011 at 7:28 PM

I wonder if it will allow you to see other variables defined from the application.cfc, like variables.someVariableIJustMadeUp or just the "official" properties of the application.

Comment 4 by Raymond Camden posted on 12/5/2011 at 7:32 PM

CF uses the This scope for settings, not the Variables scope. So that wouldn't be returned.

I just did a test where I added this.ray=1, and it DID show up, but I would not rely on that. You should not (and of course, take "should" with a grain of salt) use the This scope for your own stuff (in App.cfc I mean). You have an Application scope for that - use it.

Comment 5 by Ken posted on 12/5/2011 at 7:35 PM

Let's hope there's a corresponding way to administratively restrict VFS size on shared servers. :)

Comment 6 by Raymond Camden posted on 12/5/2011 at 7:37 PM

Ken, I'm not sure if I'm allowed to say this, but as it makes sense, I'll do so anyway.

If you set a limit of X in the CF Admin, an application is NOT allowed to go over X. And our function should actually return the right value, so you can still handle it via code. So for example, if your app needs 5 megs, and requests it, but the Admin set it to 2, you should see 2 and be able to do... well whatever makes sense for your application.

Once we have a public preview, please double check this of course.

Comment 7 by Steve Bryant posted on 12/5/2011 at 10:23 PM

This is really nice!

As with you, I find it annoying not to be able to find out information that I know my programming language must know.

Very nice stuff.

Comment 8 by Mike Kelp posted on 12/6/2011 at 5:50 PM

Nice post Ray. I agree completely that CF should not hide information. One of the empowering things about CF is that it does make so much functionality easy, but for the most part (and even more after this feature), allows you to do something special anywhere you can, losing as little benefit from the language / application server as possible.

There is nothing worse than when one development decision makes 10 other unrelated features unusable because you had to jump languages, technologies, or couldn't hook something in appropriately.

Also looking forward to the implicit getter / setter feature.

Comment 9 by erikv posted on 12/13/2011 at 1:01 AM

Any idea when this will be released? I need Axis 2 sooo bad.

Comment 10 by Raymond Camden posted on 12/13/2011 at 2:52 AM

Yep, I know exactly when it will be released.

Comment 11 by pb_ posted on 12/18/2011 at 10:07 AM

You tease... ;)

Comment 12 by Aaron Neff posted on 6/7/2012 at 12:13 PM

Hi Ray,

GetApplicationMetadata was renamed to ApplicationGetMetadata in CF10 Final.

The new doc is here: http://help.adobe.com/en_US...

The renaming was done for consistency w/ SessionGetMetadata (which itself used to be SessionStartTime): http://help.adobe.com/en_US...

Currently, getApplicationMetadata works in code and is listed by getFunctionList. Also, applicationGetMetadata does not work in code and is not listed by getFunctionList.

I've filed bug #3207841 for all of this: https://bugbase.adobe.com/i...

Thanks,
-Aaron