Alpha Video Training
Results 1 to 8 of 8

Thread: State variables vs Session variables are they equivalent?

  1. #1
    Member
    Real Name
    Clint
    Join Date
    Oct 2012
    Posts
    95

    Default State variables vs Session variables are they equivalent?

    By equivalent, I mean

    • Do State Variables last the same amount of time as Session Variables, as specified on the server?
    • In the case of State Variables, is their name automatically unique because they are associated with a ux or grid?
    • Lastly, is there any link to alpha documentation (or any website?) that compares the two? ( I tried and found nothing )


    To be clear, I know how to use both, I just don't know if one is better than the other in some way.

    Thanks

  2. #2
    Volunteer Moderator Steve Workings's Avatar
    Real Name
    Steve Workings
    Join Date
    Apr 2000
    Location
    The Dreaded Chair
    Posts
    5,619

    Default Re: State variables vs Session variables are they equivalent?

    State variables are part of the e. object, e.g. e._state.myvar1 = "value1" so they persist just as long as the component is loaded.

    Session variables are not dependent on the presence / load state of a component and are often used to persist data across components and pages so that values can be shared session-wide.

    Does that help?

    Oh - welcome to the message board!
    -Steve


  3. #3
    Member
    Real Name
    Clint
    Join Date
    Oct 2012
    Posts
    95

    Default Re: State variables vs Session variables are they equivalent?

    Quote Originally Posted by Steve Workings View Post
    State variables are part of the e. object, e.g. e._state.myvar1 = "value1" so they persist just as long as the component is loaded.

    Session variables are not dependent on the presence / load state of a component and are often used to persist data across components and pages so that values can be shared session-wide.

    Does that help?

    Oh - welcome to the message board!
    Yes it does, thank you. That answer makes the choice come down to whether I need the variable to exist after a component is no longer loaded or not.

    Thanks for the welcome.

  4. #4
    "Certified" Alphaholic mikeallenbrown's Avatar
    Real Name
    Mike Brown
    Join Date
    Nov 2009
    Location
    United States
    Posts
    1,879

    Default Re: State variables vs Session variables are they equivalent?

    Just a follow up question for Steve or anyone else in the know ...

    What type, if any, of performance hit is there when using session variables? ..thanks
    Mike Brown - Contact Me
    Programmatic Technologies, LLC
    Programmatic-Technologies.com
    Independent Developer & Consultant

  5. #5
    Volunteer Moderator Steve Workings's Avatar
    Real Name
    Steve Workings
    Join Date
    Apr 2000
    Location
    The Dreaded Chair
    Posts
    5,619

    Default Re: State variables vs Session variables are they equivalent?

    Mike - I don't consider performance an issue when deciding to create/use a session variable. It's just something stored that the server picks up when called for. I suppose you could get all sorts of discussion about the use of a bit more memory, etc but when you need one you need one. Another way to look at it is that you can create a value once and hang on to it rather than create it every time you need it. That can really add up to a time & process saving depending on your variable and how often you need it.

    Remember too that you can create a session variable, use it just until needed, then delete it as well. Some "temporary" ones that we use carry a sizable amount of text so our policy is to delete those when no longer needed.
    -Steve


  6. #6
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,759

    Default Re: State variables vs Session variables are they equivalent?

    As well... session variables are not always immediately available at the client side when you create them. A session var is created by a trip to the server and is therefore dependant on how long that takes.

  7. #7
    Volunteer Moderator Peter.Greulich's Avatar
    Real Name
    Peter Greulich
    Join Date
    Apr 2000
    Location
    Boston, MA
    Posts
    11,644

    Default Re: State variables vs Session variables are they equivalent?

    To add to this discussion.

    Session variables live on the server and are global there. You can read them from any component.

    State variables are more limited. They can be shared between a component and the server, but they are not global by any means.

    e.g.

    UX1 has state var _ux1

    Your ajax callback can see and modify that var. UX1 can see the modification made to _ux1 in the callback.

    However, neither UX2, nor Grid3, nor their callbacks, can see state var _ux1

  8. #8
    "Certified" Alphaholic Clipper87's Avatar
    Real Name
    Frank
    Join Date
    Dec 2008
    Location
    Antwerp, Belgium
    Posts
    1,891

    Default Re: State variables vs Session variables are they equivalent?

    And then there's application global variables as well (see project properties)
    Frank

    Tell me and I'll forget; show me and I may remember; involve me and I'll understand

Similar Threads

  1. State variables not work
    By Catalin in forum Mobile & Browser Applications
    Replies: 10
    Last Post: 04-10-2014, 10:31 AM
  2. State Variables in OnSummarySectionRender
    By gaby_h in forum Application Server Version 11 - Web/Browser Applications
    Replies: 1
    Last Post: 06-20-2013, 03:53 PM
  3. Caching and session variables when calling page with variables
    By nlights in forum Application Server Version 11 - Web/Browser Applications
    Replies: 11
    Last Post: 04-29-2013, 06:30 PM
  4. How to turn page variables into session variables in a grid
    By nlights in forum Application Server Version 11 - Web/Browser Applications
    Replies: 5
    Last Post: 02-25-2013, 12:47 PM
  5. Variables variables global, session or layout?
    By Greg Fong in forum Alpha Five Version 4
    Replies: 4
    Last Post: 07-11-2001, 03:54 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •