File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 60810
    
  65

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: 12761
    
    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?
 
Don't get me started about those stupid light bulbs.
 
subject: Objects in HttpSession
 
Similar Threads
Can u help me?
Doubt: K&B 1.5 p. 286; table 4-1 (´┐Ż instanceof´┐Ż)
concurrent access of session ejbs
Any Link Between ArrayList and HashMap
Hashmap