Package org.jxmpp.util.cache
Class LruCache<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<K,V>
-
- java.util.LinkedHashMap<K,V>
-
- org.jxmpp.util.cache.LruCache<K,V>
-
- Type Parameters:
K- the type of the keys of this cache.V- the type of the values this cache caches.
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.util.Map<K,V>,Cache<K,V>
public class LruCache<K,V> extends java.util.LinkedHashMap<K,V> implements Cache<K,V>
A specialized Map that is size-limited (using an LRU algorithm). The Map is thread-safe.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)java.util.Set<java.util.Map.Entry<K,V>>entrySet()Vget(java.lang.Object key)longgetCacheHits()Get the number of cache hits.longgetCacheMisses()Get the number of cache misses.intgetMaxCacheSize()Return the maximum cache Size.booleanisEmpty()java.util.Set<K>keySet()Vlookup(K key)Returns the value of the specified key, ornull.Vput(K key, V value)Put a value in the cache.voidputAll(java.util.Map<? extends K,? extends V> m)Vremove(java.lang.Object key)protected booleanremoveEldestEntry(java.util.Map.Entry<K,V> eldest)voidsetMaxCacheSize(int maxCacheSize)Set the maximum cache size.intsize()java.util.Collection<V>values()-
Methods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, merge, putIfAbsent, remove, replace, replace
-
-
-
-
Method Detail
-
put
public final V put(K key, V value)
Description copied from interface:CachePut a value in the cache.
-
lookup
public final V lookup(K key)
Description copied from interface:CacheReturns the value of the specified key, ornull.
-
get
public final V get(java.lang.Object key)
-
remove
public final V remove(java.lang.Object key)
-
clear
public final void clear()
-
size
public final int size()
-
isEmpty
public final boolean isEmpty()
-
values
public final java.util.Collection<V> values()
-
containsKey
public final boolean containsKey(java.lang.Object key)
-
containsValue
public final boolean containsValue(java.lang.Object value)
-
keySet
public final java.util.Set<K> keySet()
-
getCacheHits
public final long getCacheHits()
Get the number of cache hits.- Returns:
- the number of cache hits.
-
getCacheMisses
public final long getCacheMisses()
Get the number of cache misses.- Returns:
- the number of cache misses.
-
getMaxCacheSize
public final int getMaxCacheSize()
Description copied from interface:CacheReturn the maximum cache Size.- Specified by:
getMaxCacheSizein interfaceCache<K,V>- Returns:
- the maximum cache size.
-
setMaxCacheSize
public final void setMaxCacheSize(int maxCacheSize)
Description copied from interface:CacheSet the maximum cache size.- Specified by:
setMaxCacheSizein interfaceCache<K,V>- Parameters:
maxCacheSize- the new maximum cache size.
-
-