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):
this.mappings = {
"/foo":expandPath("./")
}; this.customtagpaths=expandPath("./"); this.sessioncookies.httpOnly = true; this.invokeImplicitAccessor = true; this.inmemoryfilesystem.enabled = true;
this.inmemoryfilesystem.size = 10;
}
component {
this.name="moo";
this.sessionManagement="true";
this.datasource="cfartgallery";
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.
Archived Comments
So is getApplicationMetaData() basically the documented version of application.getApplicationSettings()?
And supported. ;)
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.
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.
Let's hope there's a corresponding way to administratively restrict VFS size on shared servers. :)
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.
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.
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.
Any idea when this will be released? I need Axis 2 sooo bad.
Yep, I know exactly when it will be released.
You tease... ;)
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