Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Caching custom objects in JSP session

 
Sam Gardner
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Guys -

Currently, I have a bunch of "Survey" objects that I use to store various parameters of the surveys that my web application displays. These are instantiated by reading external survey definitions (currently MySQL tables, but eventually I'd like to move them to xml files or something along those lines. The key is that they are not deployed *with* the web application, and can be quickly added by non-programmers and accessed by the application without redeploying it). As it stands right now, I'm currently creating a new one of these objects by reading the parameters out of it every time I need some information about each survey (generally on each new "page" of the survey).

This really isn't necessary, as these definitions generally stay consistent throughout a user's session, so I'd like to figure out a way to initialize them once at login, and just read the parameters (the parameters aren't very huge at all - the data takes up about 400kb at worse on the tables) out of memory rather than having to hit the external data source on every page.

To accomplish this, I've tried just sticking them in the session by doing session.setAttribute(survey + "survey_parameters", surveyObject), but since Surveys are not Objects, there are all sorts of class mismatch issues.

I feel like this really shouldn't be that difficult, and that I'm missing something obvious, but I can't for the life of me figure out what it is. It would be much appreciated if someone could help me out.

Thanks!
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is casting the "obvious" thing you are missing? I.e. having to cast the result of session.getAttribute() to the Survey type?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!