Implement LRU cache. Come up with the best you can.
Sigiloso
Thread Safe LRU cache using a Queue and a HashMap import java.util.HashMap; import java.util.LinkedList; import java.util.Queue; public class LRUCache { private Queue q = new LinkedList(); private HashMap cache = new HashMap(); private int MAX_SIZE = 10; public LRUCache(int size){ this.MAX_SIZE=size; } public LRUCache(){ } public synchronized V get(K key){ return cache.get(key); } public boolean contains(K key){ return cache.containsKey(key); } public synchronized void put(K key, V value){ if(cache.size()==MAX_SIZE){ cache.remove(q.remove()); } q.add(key); cache.put(key, value); } public void add(K key, V value){ put(key, value); } }