Controlling component state, Using awake and sleep, Managing component resources – Apple WebObjects 3.5 User Manual

Page 135

Advertising
background image

Controlling Component State

135

At times, a user’s choice signals the end of a session (such as when the Yes
button is clicked in response to the query, “Do you really want to leave the
Intergalactic Web Mall?”). If you are sure a session has ended, you can send
a

terminate

message to the session object, marking it (and the resources it

holds) for release.

A session marked for release won’t actually be released until the end of the
current request-response loop. Other objects may need to know whether a
particular request-response loop is their last, so they can close files or do
other clean up. They can learn their fate by sending the session object an

isTerminating

message.

Using awake and sleep

Another strategy for managing session state is to create it at the beginning
of the request-response loop and then release it at the end. The session
object’s

awake

and

sleep

methods provide the hooks you need to implement

this strategy. A session object receives an

awake

message at the beginning of

the request-response loop (where you can reinitialize the session state) and
a

sleep

message at the end (where you can release it).

Controlling Component State

Component objects exist within a particular session and are stored along
with the session object between each cycle of the request-response loop.
Since a user can visit many pages during a session, managing component
state can be crucial to reducing your application’s storage requirements.

Managing Component Resources

Typically, page caching occurs both on the client machine and on the
WebObjects application server. WOApplication provides methods to
control caching on either end of a web connection. This section discusses
server-side caching and the section “Client-Side Page Caching” (page 139)
looks at the consequences of page caching on the client.

There are three common techniques for controlling component resources:

Adjusting the page cache size

Using

awake

and

sleep

to initialize and release resources

Controlling page instantiation by implementing

pageWithName:

Advertising