No need for a library. The built-in Java libraries suffice.
Use a ConcurrentNavigableMap.
Currently the only bundled implementation is ConcurrentSkipListMap.
Probably not appropriate to post programming details here.
If you post this same kind on Question on Stack Overflow, but asking how to do this in general rather than asking for a ...
Set browser.cache.disk.enable to false
Set browser.cache.memory.enable to true
Give some more space to memory cache if you like (defaults to 32M):
Create a new Integer entry browser.cache.memory.capacity if not already available and enter e.g. 131072 to give 128M.
Verify settings at about:cache
It's been a few months since you posted your request, but please consider FeCache
FeCache is an extremely lightweight simple caching library in Java which allows entries to be cached with different expiration times, specified in milliseconds - that is, each entry can be given a different time-to-live. I hope I'm using the term correctly here: it's FOSS, ...
WinGate has a fairly powerful event-driven policy framework which allows you to do this. You can modify requests, divert requests, or serve requests directly from a local file (or even CGI e.g. PHP) instead of from the remote server.
We offer free support, and also a free license for 10 concurrent users.
Disclaimer: I work for Qbik who are the authors of ...