Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active 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/7bf691aaba1402517f41b963bfc42e99 to your computer and use it in GitHub Desktop.
Save deque-blog/7bf691aaba1402517f41b963bfc42e99 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) {
super(capacity, 0.75f, true);
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