aspose file tools*
The moose likes JSP and the fly likes Objects in HttpSession Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Objects in HttpSession" Watch "Objects in HttpSession" New topic
Author

Objects in HttpSession

Kalichar Rangantittu
Ranch Hand

Joined: Jan 15, 2002
Posts: 240
I have a case wherein getting objects from a data source is time consuming. I would prefer to cache them in the user session in favor of performance. Does anyone have any patterns on how objects in sessions should be managed and/or evicted?


Never be satisfied with anything less than the best and you will surely pass the test...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61232
    
  66

When I employ such a mechanism I usually use a Factory class that uses lazy-loading and caching.

All access to the object is done through the factory API, so the calling code doesn't need to be concerned with the details of caching or anything else.

The factory class is responsible for loading the object and maintaining the cache, including deciding when the cache needs flushing or updating.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12789
    
    5
You might look at Whirlycache for in memory caching of misc. objects.
Depending on the session might fail unpredictably if the objects are not serializable since the servlet engine is free to serialize a session to storage any time between requests.
Bill
Kalichar Rangantittu
Ranch Hand

Joined: Jan 15, 2002
Posts: 240
Thanks for the responses. I understand that storing results in the session can be a pain. I would like to be able to store results in a cache and make it available for use across a cluster. Any tips on a cache implementation?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Objects in HttpSession