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:
Serializable,Cloneable,Map<K,,V> Cache<K,V>
A specialized Map that is size-limited (using an LRU algorithm). The Map is
thread-safe.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
ConstructorsConstructorDescriptionLruCache(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
Modifier and TypeMethodDescriptionfinal voidclear()final booleancontainsKey(Object key) final booleancontainsValue(Object value) entrySet()final Vfinal longGet the number of cache hits.final longGet the number of cache misses.final intReturn the maximum cache Size.final booleanisEmpty()keySet()final VReturns the value of the specified key, ornull.final VPut a value in the cache.final voidfinal Vprotected final booleanremoveEldestEntry(Map.Entry<K, V> eldest) final voidsetMaxCacheSize(int maxCacheSize) Set the maximum cache size.final intsize()final Collection<V> values()Methods inherited from class java.util.LinkedHashMap
forEach, getOrDefault, replaceAllMethods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, merge, putIfAbsent, remove, replace, replaceMethods inherited from class java.util.AbstractMap
equals, hashCode, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, hashCode, merge, putIfAbsent, remove, replace, replace
-
Constructor Details
-
LruCache
Create a new cache and specify the maximum size of for the cache in bytes, and the maximum lifetime of objects.- Parameters:
maxSize- the maximum number of objects the cache will hold. -1 means the cache has no max size.
-
-
Method Details
-
removeEldestEntry
- Overrides:
removeEldestEntryin classLinkedHashMap<K,V>
-
put
Description copied from interface:CachePut a value in the cache. -
lookup
Description copied from interface:CacheReturns the value of the specified key, ornull. -
get
-
remove
-
clear
-
size
-
isEmpty
-
values
-
containsKey
- Specified by:
containsKeyin interfaceMap<K,V> - Overrides:
containsKeyin classHashMap<K,V>
-
putAll
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V> - Overrides:
containsValuein classLinkedHashMap<K,V>
-
entrySet
-
keySet
-
getCacheHits
Get the number of cache hits.- Returns:
- the number of cache hits.
-
getCacheMisses
Get the number of cache misses.- Returns:
- the number of cache misses.
-
getMaxCacheSize
Description copied from interface:CacheReturn the maximum cache Size.- Specified by:
getMaxCacheSizein interfaceCache<K,V> - Returns:
- the maximum cache size.
-
setMaxCacheSize
Description copied from interface:CacheSet the maximum cache size.- Specified by:
setMaxCacheSizein interfaceCache<K,V> - Parameters:
maxCacheSize- the new maximum cache size.
-