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, replaceAllclone, compute, computeIfAbsent, computeIfPresent, merge, putIfAbsent, remove, replace, replaceequals, hashCode, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, equals, hashCode, merge, putIfAbsent, remove, replace, replacepublic 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)
Cachepublic final V lookup(K key)
Cachenull.@Deprecated public final V get(Object key)
Cachenull.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()
CachegetMaxCacheSize in interface Cache<K,V>public final void setMaxCacheSize(int maxCacheSize)
CachesetMaxCacheSize in interface Cache<K,V>maxCacheSize - the new maximum cache size.