Looking for simple Java in-memory cache

sanity picture sanity · Feb 22, 2009 · Viewed 208.2k times · Source

I'm looking for a simple Java in-memory cache that has good concurrency (so LinkedHashMap isn't good enough), and which can be serialized to disk periodically.

One feature I need, but which has proved hard to find, is a way to "peek" at an object. By this I mean retrieve an object from the cache without causing the cache to hold on to the object any longer than it otherwise would have.

Update: An additional requirement I neglected to mention is that I need to be able to modify the cached objects (they contain float arrays) in-place.

Can anyone provide any recommendations?

Answer

sanity picture sanity · Mar 25, 2013

Since this question was originally asked, Google's Guava library now includes a powerful and flexible cache. I would recommend using this.