public class LruCache<K,V> extends LinkedHashMap<K,V> implements Cache<K,V>
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
LruCache(int maxSize)
Create a new cache and specify the maximum size of for the cache in
bytes, and the maximum lifetime of objects.
|
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<K,V>> |
entrySet() |
V |
get(Object key)
Deprecated.
|
long |
getCacheHits()
Get the number of cache hits.
|
long |
getCacheMisses()
Get the number of cache misses.
|
int |
getMaxCacheSize()
Return the maximum cache Size.
|
boolean |
isEmpty() |
Set<K> |
keySet() |
V |
lookup(K key)
Returns the value of the specified key, or
null . |
V |
put(K key,
V value)
Put a value in the cache.
|
void |
putAll(Map<? extends K,? extends V> m) |
V |
remove(Object key) |
protected boolean |
removeEldestEntry(Map.Entry<K,V> eldest) |
void |
setMaxCacheSize(int maxCacheSize)
Set the maximum cache size.
|
int |
size() |
Collection<V> |
values() |
forEach, getOrDefault, replaceAll
clone, compute, computeIfAbsent, computeIfPresent, merge, putIfAbsent, remove, replace, replace
equals, hashCode, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, equals, hashCode, merge, putIfAbsent, remove, replace, replace
public LruCache(int maxSize)
maxSize
- the maximum number of objects the cache will hold. -1
means the cache has no max size.protected final boolean removeEldestEntry(Map.Entry<K,V> eldest)
removeEldestEntry
in class LinkedHashMap<K,V>
public final V put(K key, V value)
Cache
public final V lookup(K key)
Cache
null
.@Deprecated public final V get(Object key)
Cache
null
.public final void clear()
public final int size()
public final boolean isEmpty()
public final Collection<V> values()
public final boolean containsKey(Object key)
containsKey
in interface Map<K,V>
containsKey
in class HashMap<K,V>
public final boolean containsValue(Object value)
containsValue
in interface Map<K,V>
containsValue
in class LinkedHashMap<K,V>
public final long getCacheHits()
public final long getCacheMisses()
public final int getMaxCacheSize()
Cache
getMaxCacheSize
in interface Cache<K,V>
public final void setMaxCacheSize(int maxCacheSize)
Cache
setMaxCacheSize
in interface Cache<K,V>
maxCacheSize
- the new maximum cache size.