Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Created January 25, 2019 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/9ba220d4666f055f2eeb8d2c4d53b28e to your computer and use it in GitHub Desktop.
Save deque-blog/9ba220d4666f055f2eeb8d2c4d53b28e to your computer and use it in GitHub Desktop.
public class LRUCache<K, V> extends LinkedHashMap<K, V> {
private final int capacity;
public LRUCache(int capacity) {
this.capacity = capacity;
}
@Override
protected boolean removeEldestEntry(Map.Entry<K, V> oldest) {
return size() > capacity;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment