Moving to... JDBC for now. Clearly not testing, and we don't know if you're using an ORM. Not sure if this should be in beginning Java, if you're just having a problem making a hash table, or in Other Open Source Products if you plan on using an existing cache solution.
How to make a hash table? Probably use entity ID as the key, and use the entity as the value. Then look up the results from there instead of the DB.
Though you could use simple Collections to cache data there are far more sophisticated solutions out there. Have a google for "java cache" and you'll see a whole bunch of products. Also, ORMs come with levels of caching. you might consider this too.
Rajendra Prakash wrote:Instead of Retrieving database tables from DB, how can i store it in cache.
I want to improve the performance.
Better use some open source caching framework like JBoss cache. when the application starts up. retrieve everything from DB and put it in cache.When ever there is a database update/insert happens update cache too.
Paul Sturrock wrote:
How does it pick up updates made by other processes?
Some databases have a mechanism for this. For example Oracle (10g and higher) allows you to register for notifications about DML and DDL changes to tables, or even queries (11g). It's called Database Change Notification, if you want to look it up.
I'm aware of triggers, and I'm aware they can be used to call out to other processes. What I'm not aware of is any mechanism in JBoss Cache to hook into this - that's what my question is about.