Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Objects in HttpSession

 
Kalichar Rangantittu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic