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?
But what is “Cache?” A cache is an area of local memory that holds a copy of frequently accessed data that is otherwise expensive to get or compute. Examples of such data include a result of a query to a database, a disk file or a report. Lets look at creating and using a simple thread-safe Java in-memory cache.
The Java Object Cache provides caching for expensive or frequently used Java objects when the application servers use a Java program to supply their content. Cached Java objects can contain generated pages or can provide support objects within the program to assist in creating new content.
Since this question was originally asked, Google's Guava library now includes a powerful and flexible cache. I would recommend using this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With