Persistent objects:
Web based applications are stateless. Every request by the client browser is identical to the previous
one. So the server has no idea of what the client has done previously. But most applications need to
know what has happened previously so that the context of the current request can be determined. User
login is such an example --
when the user logs in caravan creates an object of the name "userinfo" and sets a cookie on the browser.
The browser sends this cookie back to the server in all subsequent requests. Caravan retrieves the
userinfo object from its memory using the cookie as a pointer. If the userinfo exists then the user is
already authenticated and the login prompt is not send again. When user logs out this object is destroyed.
In a similar manner caravan provides a facility to create persisitent objects which can be used by
the application programmer.
Suppose we need to connect to an ftp server to retrieve for some information.
After the execution of the request the the ftp object is normally destroyed.
If subsequent requests need to connect to the ftp server, one has to recreate and
reconnect the ftp object, which is time consuming. If instead the ftp object was persistent,
the connection could be used in subsequent requests without the reconnecting overhead -- assuming
that the ftp server has not already timed out the connection.
Objects can be made to persist concurrently across multiple requests by setting the persistent property.
Persistent objects are not garbage collected when the execution of the script is done. They
are destroyed after the user session ends either due to logout or a timeout. You can make an object
persist by setting its persistent property to anyvalue except "null", if you set it it to "null"
the object is destroyed at the end of execution with other objects. They are concurrent in the sense that
simultaneously executing threads may read and write to these objects.
example:
time LoginTime
LoginTime(persistent)="yes";// creates a time object which can be throughout the users' session.
Removing persistence
1.
LoginTime(persistent)="null";// reset the persistent property
2.
delete LoginTime;// delete the object explicitly