I'm looking for recommendations for libraries that help me create an efficient and fast object value cache in Java.
My needs are as follows:
- Write: There are up to like 50000 writes per second to the cache. The good news is that all writes happen from a single thread. Inserts/deletes are rare, what actually changes are the values of the individual objects in the cache. (see below)
- Read: Read's are quite infrequent. Perhaps once every 10 second. Reads can happen from any thread. There aren't many readers. (most of the time just one, but up to let's say 3 readers)
- Cache management: There's no need for automated eviction. In fact, any eviction is always explicit (a delete operation, so to speak)
- Memory size: Not much of a problem. I may have 20k objects in the cache, maximum, and they can easily fit inside any heap.
Each object in the cache is essentially a wrapper around a key/value pair map. Through the lifetime of a cached object this map doesn't expand, nor shrink (meaning keys are always the same). What changes are the values in the key/value pair map. Writes must be done in an atomic operation, meaning that a reader must not be able to read from an object while it is being written to.
- Are there any libraries I should look at ?
- Are there any techniques I should look at? (for example in terms of reducing lock contention)
All in all you can think of an analogy of a database table. The cache is equivalent to the table in this analogy. There aren't many INSERT/DELETE operations on the table, but there's a tremendous amount of UPDATE operations. And we will not allow dirty reads.
(no, my use case has nothing to do with databases, I do not need persistence, I only mention database table because it is an good analogy)
I'm sure problems similar to this has been tackled before so I would rather like to piggy-back on someone else experience. However most of the libraries I have been able to find seem to cater for the case where there's some backend which is slow and hence it makes sense to cache a result. (which means you need to deal with things like eviction, staleness, off-heap storage, sharding, distributed, and what not, ... things that are completely irrelevant in my case)