public class LruCache<K,V> extends java.util.LinkedHashMap<K,V> implements Cache<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(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet() |
V |
get(java.lang.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() |
java.util.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(java.util.Map<? extends K,? extends V> m) |
V |
remove(java.lang.Object key) |
protected boolean |
removeEldestEntry(java.util.Map.Entry<K,V> eldest) |
void |
setMaxCacheSize(int maxCacheSize)
Set the maximum cache size.
|
int |
size() |
java.util.Collection<V> |
values() |
clone, compute, computeIfAbsent, computeIfPresent, 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.public final V put(K key, V value)
Cachepublic final V lookup(K key)
Cachenull.@Deprecated public final V get(java.lang.Object key)
Cachenull.public final V remove(java.lang.Object key)
public final void clear()
public final int size()
public final boolean isEmpty()
public final java.util.Collection<V> values()
public final boolean containsKey(java.lang.Object key)
public final boolean containsValue(java.lang.Object value)
public final java.util.Set<K> keySet()
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.