locomotive.org


Virtual Sessions and Caching

Note: The virtual sessions and caching mechanisms described below are under development and are subject to change as they are refined.

"Virtual sessions" is the name of a feature that enables certain kinds of data caching when multiple instances of the Locomotive operate in the same pool. With virtual sessions, a user's requests are routed to the same instance of the Locomotive for the duration of the session. This means that information like preferences can be cached by the Locomotive, avoiding potentially expensive database queries. Of course, this information could be cached without virtual sessions, but then the Locomotive instances would have to share cached data with one another, which can be difficult to coordinate.

As a module developer, virtual sessions are all you need to implement a cache in the Locomotive. In your handler or servlet, just add a static data structure such as a Hashtable, along with some synchronized methods for accessing it.

However, there is already a caching mechanism built into the Locomotive that reaps the benefits of virtual sessions, called the Locomotive Global Cache. Currently, we're in the process of adding documentation about how to use the Global Cache, but the cache itself is finished and released. If you are interested in using it, refer to the Java API documentation for the two pertinent classes: