Methods under app VS under session

Hi,
What are the differences and consequences (if on my webapps) I create the methods under app vs under the session ?
thanks

When created under the session, the methods and their data are specific to the session. When created under the app, the methods and their data are (or can be) common to all sessions.

Methods that send messages to all users (for example, maintenance warnings) may certainly be at app level. Any method dealing with data that is specific to a user should be placed under the session or within pages or containers.

That’s not entirely true. With methods It has more to how they’re called. A method on the app class that is called in response to an event on a particular session would still be in the context of that session.

Now, properties and events are another matter. Properties which are defined on the session object and events that fire on the session are definitely unique to each session. Whereas properties on the app class or a module will be accessible from any session simultaneously.

Thank you for the clarification @Greg O’Lone.

Greg, I frequently use global public properties - do you recomend me to put globals under session instead of under app ?
Just in case ?
thanks

This is very interesting… Would an application use less memory if the methods are at the App level, even if they are called at the Session level?

I currently put almost 100% under the session, but it might make more sense for the majority of the “application” to be under the App level, and then the sessions specific methods/etc within the session only.

@Robert Litchfield : My guess is that a method uses memory while it runs. Regardless where it is located in code (App, Session, Page or Container), it will use the same quantity of memory, give or take.

@Horacio Vilches : the key question is whether the data can be different across sessions. If it is the same and remains static, then app level is OK. If it can be different across sessions, then you should move the property to the session. And if the property can contain customer data, then for sure it should not be at app level where anyone could read it. For example, my database connexions are at Session level, and verified to be active before any method using them.

You are probably correct @louis desjardins … I thought there might be a possibility that if the method is in memory, and shared between the sessions, the overall footprint could be different rather than a separate method for each session.

In either case, a stack frame is allocated to hold local and temporary variables, the code itself exists only once. So there is no difference where the code is created. The memory footprint will be identical.

[quote=404884:@Horacio Vilches]Greg, I frequently use global public properties - do you recomend me to put globals under session instead of under app ?
Just in case ?
thanks[/quote]
It depends on what they are for. If your app expects them to be unique per session, then they should be part of the Session object. If not, they can be anywhere.

but it is not possible to create the module globals under session I have to put the properties directly under session. Not a big difference right ?

Properties are a big difference. Properties defined on the Session object are unique to each user. Properties defined elsewhere… like under App or another Module are global and therefore all Sessions share those values.

And a special case are static variables, those act like global variables even if they are defined in a session. So if session A has a static variable called ‘bg’ with a value of blue for background color and session B changes the value of ‘bg’ to red, the change will also affect the background in session A. This can give funny effects and hard to trace bugs.

…properties I create under session cause the error “does not exist” even if I use the prefix session.property.
So I create my properties under webpage. I hope that in this case, under webapge they are not shared on different sessions. What do you think ? I’m guessing because I dont have the full version so my experiments are limited.

Properties of Webpage are only accessible to that page for that session.
Properties of Session are accessible from every page for that session.
Properties of App are accessible from all pages of all sessions.

Your version is not limited in functionality, only in the ability to build a final app. Your “does not exist” errors are not caused by that. You should be able to access the session variables, so there is something else going on. Where is the code that is trying to access the session variable? In a webpage? In Session? In a module?

[quote=405286:@Tim Hare]Properties of Webpage are only accessible to that page for that session.
Properties of Session are accessible from every page for that session.
Properties of App are accessible from all pages of all sessions.[/quote]
It should be noted that these things also depend on the “scope” of the property. If they are defined as private or protected, trying to access them as Session.PropName won’t work either.