• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overusing session object?

 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic