import java.util.HashMap; import java.util.Map; public class Cache { private final Map cache; public Cache() { cache = new HashMap<>(); } public synchronized void put(K key, V value) { cache.put(key, value); } public synchronized V get(K key) { return cache.get(key); } public synchronized boolean hasKey(K key) { return cache.containsKey(key); } public synchronized void remove(K key) { cache.remove(key); } }