Note: The pageWithName: method shown in the section "Action Methods" always creates a new component object, even if page caching is turned on.
// WebScript EmployeeBook Department.wos id departments; - init { id departmentsPath; [super init]; departmentsPath = [[self application] pathForResourceNamed:@"Departments" ofType:@"array"]; departments = [NSArray arrayWithContentsOfFile:departmentsPath]; return self; }The component awake method is invoked immediately after the init method and each time the component object is restored from the page cache. Just as in init, you can implement an awake method that initializes component variables. For example, in the DodgeDemo application, the Car.wos script uses awake to initialize the shoppingCart component variable:
// WebScript DodgeDemo Car.wos - awake { shoppingCart = [[self session] shoppingCart]; }In general, you use init to initialize component instance variables instead of awake. The reason is that init is invoked only at component initialization time, whereas awake is potentially invoked much more than that. If, however, you want to minimize the amount of state stored between cycles of the request-response loop, you might choose to initialize component instance variables in awake and then deallocate them in sleep (by setting them to nil in WebScript or null in Java). For more information, see the chapter "Managing State".
Table of Contents Next Section