Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes should I load product info into memory or keep in db? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "should I load product info into memory or keep in db?" Watch "should I load product info into memory or keep in db?" New topic
Author

should I load product info into memory or keep in db?

Henry Sun
Greenhorn

Joined: May 09, 2003
Posts: 18
Hi,
I am going to develop a b2c shopping website with jboss-tomcat bundle. Now I must make a decision on whether I should load product info into memory or just keep it in table. If load into memory, the performance of customer browsing and searching will be good; but I am afraid of the memory capacity and issues like, when I want to update the product price or description, I need to refresh the memory objects. This shop has about 500 products and we will develop this application into Dell server with 1GB memory. Can anyone who has ever developed such e-commerce website give me some suggestions?
Thanks.
Henry
Paul Lester
Ranch Hand

Joined: Dec 27, 2002
Posts: 40
Hello, Henry: Considering that you have only 500 items, any database, including M$ Access should be able to give you nearly instantaneous access to any record; therefore, you won't notice much difference between hitting the database and caching the records.
Caching should be done only after careful consideration. One of the biggest problems, as you mentioned, is how to refresh the objects as well as how often to refresh them. Then there are the memory constraints, etc. I would steer away from caching your entire product line. If the number of products continue to grow then you are going to start having issues with memory.
Keeping the information in the database allows you to update or remove items easily and without an application restart. Further, if you determine that it is too slow you can add indexes, get faster hardware, etc.
Lastly, deciding whether or not to cache, in the design stages, is a bit premature. You should come to that decision AFTER you've done some profiliing of the application and found that the DB portion is indeed the bottleneck of the application.
Regards,
Paul


Where Photography meets vision.<br /><a href="http://www.photogravision.com" target="_blank" rel="nofollow">http://www.photogravision.com</a><br />Please stop by!<br /> <br />SCJP,SCWCD,SCJD,SCEA
Henry Sun
Greenhorn

Joined: May 09, 2003
Posts: 18
Thank you, Paul. I prefer keeping the pruducts in database instead of memory. I'll do some profiling, just like you said, then make the final decision.
Henry
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

One of the best bits of advice I can give is not to worry about efficiency more than you need to. It's not like there's only one "right" way to do things.
I've found that it's a good idea to keep the design "loose" so that mods can be made as needed rather than to try and anticipate problems that may never occur. Especially if solving these non-problems is going to lock you out of being able to address the problems that do occur.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: should I load product info into memory or keep in db?
 
Similar Threads
Design question
Location for configuration files and hbm files
Bought SCJP6 online, when will receive the vouch?
Tiles: Portal layout ?
JDBC multiple statements in prepatedStatement?