This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JDBC and the fly likes How to store Database tables in Cache Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to store Database tables in Cache " Watch "How to store Database tables in Cache " New topic
Author

How to store Database tables in Cache

Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
Instead of Retrieving database tables from DB, how can i store it in cache.
I want to improve the performance.
Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
I have been asked to create a hashtable from the table in the db.
How can i do this.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Subin Sugunan
Greenhorn

Joined: Jul 01, 2009
Posts: 14
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.


Thanks and Best Regards
Subin Sugunan
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


When ever there is a database update/insert happens update cache too.

How does it pick up updates made by other processes?
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

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.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to store Database tables in Cache