I want to implement a Cache in Java that is supposed to cache tags for a given id. (0-N tags for one id)
There are around 1000 unique tags in 100 million entities, but the actual number can vary by a few thousand.
It does not not need to consider id/tag eviction.
It is expected for the cache to throw a OutOfMemoryError if more tags exist than we can cache in memory.
However, the design should ensure that it takes as little memory as possible to cache the tags.
The cache has one method 'getTags()' method that takes an id and returns the tags for the entity.
This method on worst case ( barring garbage collection) take a few 100 nano seconds. It can be called 1000's of time in a few milliseconds. The cache should be designed for multi threaded access with 1000's of requests to getTags in a few ms.
Please suggest a good data structure/Collection to use which can offer me such a performance.