[Looking for Charlie's main web site?]

How to determine your current client storage value

Note: This blog post is from 2008. Some content may be outdated--though not necessarily. Same with links and subsequent comments from myself or others. Corrections are welcome, in the comments. And I may revise the content as necessary.
This may be a surprise to some: it was to me.

I learned today for the first time that it's possible to find out (in code) for a given CFML app what client storage repository it's using:

<cfdump var="#Client.getPersistSettings().get("clientstorage")#">

Thanks go to Paul Kenney, as I found it in a page of his while I was doing a google search for some related info.

Why is this interesting?

I'm sure some may be wondering what the excitement is. Can't you easily tell what client storage repository a given app is using by looking at the ClientStorage attribute (of CFApplication when using application.cfm), or as a property in application.cfc? Sure.

But sometimes you may be left wondering how to view that value programmatically. Maybe you can't open those files (ok, that's a stretch), or maybe they include or invoke other application files, and trying to track those down is a hassle.

Also, one might not set the value in ClientStorage, in which case CF takes the default from the CF Admin, but a developer may not have access to the CF Admin, so can't know which repository they're really using.

How I found it, why I was looking

This came up when someone raised a problem on the Adobe Forums, where they said that several apps using a given clientstorage DSN worked, while one using it failed (all on the same server). I thought that odd, and wondered if the others may not really be using the DSN he thinks they are.

So I set off to find an answer. I hoped it might be in the servicefactory clientscopeservice, but it was not, in any of its available methods. While looking for possible examples of folks using that in ways I had not thought to, I found Paul's page above. What's nice about it is that it DOES NOT rely on the ServiceFactory, which of course is undocumented and unsupported (and can be disabled).

Some other thoughts about this getPersistSettings approach

This getPersistSettings approach above is just an undocumented method in the regular client scope: you won't see the value or this method being exposed in a simple dump of the client scope. But at least (unlike the servicefactory) it can't be disabled.

And I've tested it in CF7 and 8, and it worked fine.

Of course, if you're going to run this to help someone determine what storage they're using, you need to run it in the directory of whatever app you're trying to check. Be careful about mistakenly running it in some test directory outside of the app's directory.

And don't bother looking for other properties to "get". The only key in the structure that's returned by getPersistSettings is this one.

That said, it would be nice if it might also identify info about the client variable storage repository, such as how many days at which it's set to purge expired visitors, and whether "disable global variable updates" is enabled or not. You can get that info using the undocumented ClientScopeService in the ServiceFactory (just do some googling for info on it, and its available getclientstores method.) But it would be nice to have this info using the method above.

In fact, I've filed a feature request to get even this current clientstorage setting (and the info about the storage repository) available in a more direct and supported manner.

In the meantime, hope this may help some.

For more content like this from Charlie Arehart: Need more help with problems?
  • If you may prefer direct help, rather than digging around here/elsewhere or via comments, he can help via his online consulting services
  • See that page for more on how he can help a) over the web, safely and securely, b) usually very quickly, c) teaching you along the way, and d) with satisfaction guaranteed
Comments
Another "undocumented" method that might help is the:

APPLICATION.GetApplicationSettings()

This will give you the settings that were selected for the application:

http://www.bennadel....

I am not sure if it gives you the *same* settings that you would get from inspecting the CLIENT scope, but there is a "ClientStorage" attribute.
Hi Charlie, thanks for the post! The link to Paul's page appears broken...?
# Posted By Mischa | 12/2/08 3:30 PM
@Ben, great stuff as always. Thanks. I can confirm that yes, the value reported for clientstorage there is indeed the same as what I've noted above.

I'd love to find more of these available methods buried in various scopes, but it's not really easy to find, as far as I can tell (even studying the servicefactory clientscopeservice, where I don't see any getpersistsettings method or anything like it.) If anyone knows any tricks for finding (or knows of somewhere showing a list of) these methods buried in the scopes, please let us know.

@Mischa, how so? I just tested it again and I see the page. Maybe you're thrown by it showing source code. That's what it should be. Sorry I didn't clarify that above. It's a dump of a context.cfm custom tag of his. Or are you saying you get some sort of 404 error? I don't. (I do appreciate the heads up if you or anyone find a broken link in my stuff, so thanks.)
I used to use Java Reflection all the time to play around with objects:

http://www.bennadel....

I haven't done it lately, but its in my testing environment so I can call on it when necessary.
David Stamm has a object inspector that puts mine to SHAME! Not sure if he made it public. I'll send him this way.
Awesome, Ben. Thanks again. I just ran that code against the client scope and indeed the getpersistsettings is there, as are a couple other interesting ones, like getglobalvars (reporting the "global variables" that are enabled by default for client vars), getrefcount (which I haven't quite figured out yet), and some others (including some is* functions, like isClientIdFromUrl).

And of course there are many interesting ones for the session scope, too. Will look forward to any further help David's code may offer.
I will ping Dave about this post.
Hmmm, works now... strange, I got an error other than your 404 or "page could not be displayed"... maybe somehow the cfm extension wasn't properly processed on my work pc.
# Posted By Mischa | 12/2/08 9:31 PM
Copyright ©2024 Charlie Arehart
Carehart Logo
BlogCFC was created by Raymond Camden. This blog is running version 5.005.
(Want to validate the html in this page?)

Managed Hosting Services provided by
Managed Dedicated Hosting