• Post Reply Bookmark Topic Watch Topic
  • New Topic

HashMap caching stale data  RSS feed

 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using HashMap as caching (not using JBoss cache/ coherence caching) to store large number of records from DB. How should I find stale data, if DB records are updated.
 
Tim Cooke
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying to roll your own database cache is fraught with danger. You question about purging stale items is just the tip of the iceberg.

Use an "off the shelf" caching framework such as ehcache.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you caching in the first place, if you use a DB?
 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you caching in the first place, if you use a DB?


To avoid multiple calls to DB.


Use an "off the shelf" caching framework such as ehcache.


We should not use any caching framework.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kri shan wrote: . . . To avoid multiple calls to DB. . . .
Why? If your database has been updated, you will be using stale data.
 
Tim Cooke
Marshal
Posts: 4051
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We should not use any caching framework.

This seems like an unreasonable restriction. Given the fact that you are intending to implement your own caching framework anyway, why not use one that already exists?
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Cooke wrote: . . . This seems like an unreasonable restriction. . . .
It is unreasonable, unless the exercise is about creating caching frameworks.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
People have been writing "open source java cache" toolkits since Java 1.02 - do that google search, check out the design parameters other people have used, grab some example code to see how they did it.

Bill
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!