Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help in Implementing cache using hashmap

 
Sam Baheerathan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I m developing employee management system using java and enterpriseDb. in this system i m planning to manage the employee details in a hash-map to reduce the disk I/O s. since this system will be used in several machines, i need to find a way to update the hash-map when ever a employee record is updated in the database. so that all the machines can have the latest updated records.
can anyone suggest me a way to implement this?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A google search for "java cache open source" found an enormous number of hits.

People have been fiddling with caching since Java 1.0

Bill
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would take Bill up on his suggestion. Developing a good cache is not trivial. How do you invalidate a cache ? When does a cache become stale ? When do you refresh the cache ? How do you deal with concurrency ? etc etc

There are many caching solutions that can sit between the caller and the DB. They should help.
 
Sandeep Murthy
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can give "Hibernate" a try for starters.
 
Winston Gutkowski
Bartender
Pie
Posts: 10499
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Baheerathan wrote:I m developing employee management system using java and enterpriseDb. in this system i m planning to manage the employee details in a hash-map to reduce the disk I/O s. since this system will be used in several machines, i need to find a way to update the hash-map when ever a employee record is updated in the database. so that all the machines can have the latest updated records.
can anyone suggest me a way to implement this?

Well, LinkedHashMap has some goodies that allow you to implement LRU (least-recently-used) caches quite easily. Specifically, have a look at the removeEldestEntry() method.

However, you haven't really given us enough information to give you informed advice.

Winston
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic