*
The moose likes JSP and the fly likes overusing session object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "overusing session object?" Watch "overusing session object?" New topic
Author

overusing session object?

Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
I my JSP application I have reference fields that display data from other tables in drop-down box. So, I might have a reference field codes that display 1000 different codes from codes table. The problem is that once I have 2 or 3 of these reference fields when I move from record to record in my database, page loading becomes very slow since application has to select data from reference tables each time. I thought about not selecting from reference tables each time, but select data once when application loads and save all information in a file or session object. Saving in file might not make a significant difference since there is an overhead of reading from multiple files. Session I am not sure. Is it a good idea to save 2 or more arrays with 1000-2000 records in session object?
thanks,
Alex


All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

Caching data like this, rather than going back to the DB each and every time for data that doesn't change, is very common.
However, storing it in the session only makes sense if the data is different user-to-user. If the data is common across all users, storing it in application scope (aka the servlet context) makes more sense.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
Storing data in application scope is not good since different users will need to see different data. Then what is better approach: storing in files or sessions? And will storing in session put a big load on session object?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

Whether it's stored on the session or elsewhere in memory is moot. It's just memory. One advantage of putting it on the session (since it will be specific to each user), is that when the session goes out of scope, the references will be removed and the data is subject to garbage collection.
The decision is files vs. memory. And if you are going to go the file route, I'd just leave it in the DB rather than bother with files.
Roland Barcia
author
Ranch Hand

Joined: Apr 15, 2004
Posts: 181
However, in a clustered environment, session could be replicated to other nodes or stored in a persistent store. Session should not go past 4 K per user. Session is a place to keep track of the user, not a data cache. You should use data caching and store the keys in session. Use the keys in sesison against your data cache.
Even if your app is not clusterd, it could be sometime in the future.


Roland Barcia: IBM Distinguished Engineer, CTO Mobile for Lab Services
 
Consider Paul's rocket mass heater.
 
subject: overusing session object?
 
Similar Threads
Need help with a record management app.
Yes! Passed! 388/400
Local Cacheing of data from database and using it
Rule based systems
Performance Problem?