Setting session time-out – Apple WebObjects 3.5 User Manual
Page 134

Chapter 7
Managing State
134
much state is stored. This section takes a closer look at how you manage
sessionwide state.
Take care that your application only stores state for active sessions and stores the
smallest amount of state possible. WOSession lets you control these factors by
providing a time-out mechanism for inactive sessions and by providing a way to
specify exactly what state to store between request-response loop cycles.
Setting Session Time-Out
By assigning a time-out value to a session, you can ensure that the session will
be deallocated after a specific period of inactivity. WOSession’s
setTimeOut:
method lets you set this period and
timeOut
returns it.
Here’s how the session time-out works: After a cycle of the request-response
loop, WebObjects associates a timer with the session object that was involved in
the request and then puts the session object into the session store. The timer is
set to the value returned by the session object’s
timeOut
method. If the timer goes
off before the session is asked to handle another request, the session and its
resources are deallocated. A user submitting a request to a session that has timed
out receives an error message:
Figure 35. A Session Time-Out Error Message
By default, a session object’s time-out value is so large that sessions effectively
never expire. You should set the session time-out for your application to the
shortest period that seems reasonable. For example, to set the time-out to ten
minutes, you could send this
setTimeOut:
message in your session’s initialization
method:
// WebScript Session.wos
- init {
[super init];
[self setTimeOut:600];
return self;
}
// Java Session.java
public Session() {
super();
this.setTimeOut(600);
}
The argument to
setTimeOut:
is interpreted as a number of seconds.