• Post Reply Bookmark Topic Watch Topic
  • New Topic

Caching Data in JSP

 
Jerson Chua
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have several drop down list on my JSP page and their values are retrieved from the database every time the page is requested.
I find this to be inefficient. So I would like to know how do you guys implement the caching mechanism for these values? How do you find out if the value in the database has been changed?
Thanks.
 
Greg Charles
Sheriff
Posts: 3010
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember, JSPs are just Java code running on your server. Therefore the problem of caching data is solved the same way it would be in a regular application, i.e. store it in an object. Ensuring the data is not stale is more complicated. You could put a timestamp in the object every time you went out to the database, then when a request came in for the data, decide whether it was worth checking for an update. You could also use an Entity Bean, which will guarantee you get current data, but might be overkill for your situation.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JavaBean with "application" scope would probably work just fine. Like Greg says, you might use a timestamp to force it to regenerate the values ever so often.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!