public class LRUCache extends LinkedHashMap implements Cache
Cache that stores the most recently used elements. Once the cache reaches
capacity, the least recently used elements will be removed.AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>| Constructor and Description |
|---|
LRUCache(int capacity) |
| Modifier and Type | Method and Description |
|---|---|
int |
getCapacity()
Returns the maximum number of elements the cache can hold.
|
int |
getSize()
Returns the current size of the cache.
|
boolean |
isFull() |
protected boolean |
removeEldestEntry(Map.Entry eldest) |
int |
setCapacity(int capacity)
Set the maximum number of elements the cache can hold.
|
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, replaceAll, valuesclone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, sizeequals, hashCode, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, sizepublic LRUCache(int capacity)
capacity - the maximum number of elements that can be contained in the cache.public boolean isFull()
protected boolean removeEldestEntry(Map.Entry eldest)
removeEldestEntry in class LinkedHashMappublic int setCapacity(int capacity)
CachesetCapacity in interface Cachepublic int getCapacity()
CachegetCapacity in interface CacheCopyright © 2023. All rights reserved.