For a persistence service we needed a local cache. We decided to use a least recently used cache which allows to set a maximum size and automatically deletes the oldest elements.
A simple implementation based on the Java-Class LinkedHashMap can be found here:
Usage:
LRUCache<String, String> myCache = new LRUCache<String, String>(10);
If you need to access the cache with multiple threads, you can use the static Collections.synchronizedMap method:
Collections.synchronizedMap(new LRUCache<String, String>(CACHE_SIZE));
