File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to store Database tables in Cache

 
Rajendra Prakash
Ranch Hand
Posts: 293
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of Retrieving database tables from DB, how can i store it in cache.
I want to improve the performance.
 
Rajendra Prakash
Ranch Hand
Posts: 293
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been asked to create a hashtable from the table in the db.
How can i do this.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Subin Sugunan
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 3747
62
Chrome Netbeans IDE Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic