Web Software Architecture and Engineering – Life on the Bleeding Edge

Remember client scope. Ahhh yes, ye olde client scope. I remember 7 years ago, when I stopped using client scope all together, I missed having variables such as client.lastVisit, client.hitCount, and client.TimeCreated. There are several solutions to mimic the first two, but I never found anything that I felt really truly suited me. I’ve had enhancement requests with Adobe since CF7 days to add this functionality to the session scope, and I remember once when Ray and I barraged Macromedia about it.
Lately I started playing with a java taglib that provided some of the functionality I was looking for. More info on the taglib can be found @ http://www.servletsuite.com/servlets/sessinfotag.htm. Immediately I saw its uses.
Again, I’ve only quickly played with this, but it looks promising. I created a directory off the webroot. I downloaded the JAR and TLD file there. (Probably don’t need the TLD file.)
The JAR exposes 4 methods:

  1. sessionUsedTime: Which answers the question: How long has it been since this session was created? From that you could also extract exact time it was created similar to client.timeCreated.
  2. sessionInactiveTime: ** THE MOST USEFUL! ** Which answer the question: How long since the session was touched? Similar to client.lastVisit.
  3. isNewSession: Self explanatory.
  4. isNotNewSession: Self explanatory.

Let’s explore numbers 1 and 2 above. Take a look at this code.

<cfimport taglib="sessinfotag.jar" prefix="random">
<random:sessionUsedTime formatted="true" />
<random:sessionInactiveTime formatted="true" />

That’s it. Hit refresh, and watch the “time created” and “last visit” equivalent counts go up. Very easy and useful.
Advantages:

  • Native JAVA session integration
  • Less code – Just a couple lines
  • Support for multiple windows in the browser (which other code solutions have a hard time with)

Enjoy!

Advertisements

Comments on: "Session Info – New Tools for Session Scope Lovers" (7)

  1. Just checked the java files from servletsuite jar referenced above. They are in fact using getPageContext().getSession(), so we should be okay using it as well.

    From their SessionTTLTAG…

    HttpSession httpsession = pageContext.getSession();
    long l = 0L;
    if(null != httpsession)
    l = (long)(1000 * httpsession.getMaxInactiveInterval()) – (System.currentTimeMillis() – httpsession.getLastAccessedTime());

  2. Actually should be able to get most of this without the need for the jar/tld. Do a cfdump of the following and check out the methods contained:

    #getPageContext().getSession()#

    Some of the methods are:
    getCreationTime()
    getLastAccessedTime()
    getMaxInactiveInterval()
    isNew()
    getId()

  3. I believe there is an issue with using these. If you reference them, it actually changes their values. I’ll try and look up what I found while working on this a few years back.

  4. @Robert,

    That’s really interesting. I’ll have to go back and compare and see if it makes a difference. This should be a good test with CF8.

  5. Danny Armstrong said:

    Are there any follow ups to this post?

    The 4th comment would seem to invalidate this approach – it would suffer the same results as accessing it directly, which of course resets the values.

    Any thoughts on how it works, if it does?

    Guess I’ll have to give it a shot anyway.

  6. You seem to have got the niche from the root, Awesome work

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: