Inherits from: NSObject
Package: com.apple.yellow.webobjects
WOSessionStore, an abstract superclass, offers an object abstraction for storing client state per session. The application object ( WOApplication) uses an instance of a concrete WOSessionStore subclass to implement a strategy for storing and retrieving session state. You typically set the WOSessionStore during application initialization through WOApplication's setSessionStore method.
An application first creates a session ( WOSession) when it receives a request without a session ID. When this first request has been handled, the application stores the WOSession object under a randomly generated session ID by invoking its own saveSessionForContext method. This method by default forwards the message to the chosen WOSessionStore and that WOSessionStore takes care of the details of saving session state. When the next request comes in for that session, the application restores the session by sending itself restoreSessionWithID, which by default is forwarded to the application's WOSessionStore. The WOSessionStore then asks the WOContext of the transaction for the session ID of the session. Based on the implementation of the WOSessionStore, the session object is located and returned.
There is one subclass of WOSessionStore implemented for the developer's convenience. A server WOSessionStore (the default) stores session state in the server, in application memory. The serverSessionStore method returns this WOSessionStore.
See the chapter "Managing State" in the WebObjects Developers Guide for the purposes, mechanisms, and limitations of session store in the server, page, and cookies.
You can create a custom session store by making a subclass of WOSessionStore. The subclass should properly implement the saveSessionForContext and restoreSessionWithID methods (using the session ID as the key for storage) and should have a public method that the application object can use to obtain an instance. Some interesting session stores could be:
If you create your own WOSessionStore class that generates persistent objects, you should implement an algorithm that cleans up session state after the session is inactive for a long time. The server WOSessionStore provided by WebObjects performs this clean-up properly, but the API is not yet public.
- Obtaining a session store
- serverSessionStore
- Checking a session in and out
- checkInSessionForContext
- checkOutSessionWithID
- Saving and restoring a context
- restoreSessionWithID
- saveSessionForContext
public static WOSessionStore serverSessionStore()
State storage in the server is the most secure and is the easiest to implement. You can also easily manage the amount of storage consumed by setting session timeouts, limiting the size of the page-instance cache, and page uniquing. (See "Managing State" in the WebObjects Developers Guide for details on these techniques.)
You may use the coding constructor for the session ( WOSession(NSCoder)) to restore session state from the archived data.
public void checkInSessionForContext(WOContext aContext)
public WOSession checkOutSessionWithID(
String aSessionID,
WORequest aRequest)
public WOSession restoreSessionWithID(
String aSessionID,
WORequest aRequest)
The default implementation of this method does nothing
public void saveSessionForContext(WOContext aContext)
You may use the NSCoding interface method encodeWithCoder to save session state to archived data.