Skip to content

Instantly share code, notes, and snippets.

@tolinwei
Created September 24, 2016 22:02
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 tolinwei/3f0df4b5f31d53d043a1ccaf8c5c56c6 to your computer and use it in GitHub Desktop.
Save tolinwei/3f0df4b5f31d53d043a1ccaf8c5c56c6 to your computer and use it in GitHub Desktop.
public class LRUCache extends LinkedHashMap<integer, string=""> {
private int cacheSize;
public LRUCache(int size) {
super(size, 0.75f, true);
this.cacheSize = size;
}
@Override
protected boolean removeEldestEntry(
java.util.Map.Entry<integer, string=""> eldest) {
// remove the oldest element when size limit is reached
return size() > cacheSize;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment