V - type of values stored in the Mappublic class Long2ObjectCache<V>
extends java.lang.Object
implements java.util.Map<java.lang.Long,V>, java.io.Serializable
The eviction strategy is to remove the oldest in a set if the key is not found, or if found then that item. The newly inserted item becomes the youngest in the set. Sets are evicted on a first in, first out, manner unless replacing a matching key.
A good set size would be in the range of 2 to 16 so that the references/keys can fit in a cache-line (assuming references are 32 bit references and 64 byte cache lines, YMMV). A linear search within a cache line is much much less costly than a cache-miss to another line.
Null values are not supported by this cache.
| Modifier and Type | Class and Description |
|---|---|
class |
Long2ObjectCache.EntryIterator |
class |
Long2ObjectCache.EntrySet |
class |
Long2ObjectCache.KeyIterator |
class |
Long2ObjectCache.KeySet |
class |
Long2ObjectCache.ValueCollection |
class |
Long2ObjectCache.ValueIterator |
| Constructor and Description |
|---|
Long2ObjectCache(int numSets,
int setSize,
java.util.function.Consumer<V> evictionConsumer) |
| Modifier and Type | Method and Description |
|---|---|
long |
cacheHits()
The number of times a cache hit has occurred on the
get(long) method. |
long |
cacheMisses()
The number of times a cache miss has occurred on the
get(long) method. |
long |
cachePuts()
The number of items that have been put in the cache.
|
int |
capacity()
Get the total capacity for the map to which the load factor will be a fraction of.
|
void |
clear()
Clear down all items in the cache.
|
V |
computeIfAbsent(long key,
java.util.function.LongFunction<? extends V> mappingFunction)
Get a value for a given key, or if it does ot exist then default the value via a
LongFunction and put it in the cache. |
boolean |
containsKey(long key)
Overloaded version of
Map.containsKey(Object) that takes a primitive long key. |
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
Long2ObjectCache.EntrySet |
entrySet() |
boolean |
equals(java.lang.Object o) |
V |
get(long key)
Overloaded version of
Map.get(Object) that takes a primitive long key. |
V |
get(java.lang.Object key) |
int |
hashCode() |
boolean |
isEmpty() |
Long2ObjectCache.KeySet |
keySet() |
V |
put(long key,
V value)
Overloaded version of
Map.put(Object, Object) that takes a primitive long key. |
V |
put(java.lang.Long key,
V value) |
void |
putAll(java.util.Map<? extends java.lang.Long,? extends V> map) |
V |
remove(long key)
Overloaded version of
Map.remove(Object) that takes a primitive long key. |
V |
remove(java.lang.Object key) |
void |
resetCounters()
Reset the cache statistics counters to zero.
|
int |
size() |
java.lang.String |
toString() |
Long2ObjectCache.ValueCollection |
values() |
public Long2ObjectCache(int numSets,
int setSize,
java.util.function.Consumer<V> evictionConsumer)
public long cacheHits()
get(long) method.get(long) method.public long cacheMisses()
get(long) method.get(long) method.public long cachePuts()
public void resetCounters()
public int capacity()
public int size()
size in interface java.util.Map<java.lang.Long,V>public boolean isEmpty()
isEmpty in interface java.util.Map<java.lang.Long,V>public boolean containsKey(java.lang.Object key)
containsKey in interface java.util.Map<java.lang.Long,V>public boolean containsKey(long key)
Map.containsKey(Object) that takes a primitive long key.key - for indexing the Mappublic boolean containsValue(java.lang.Object value)
containsValue in interface java.util.Map<java.lang.Long,V>public V get(java.lang.Object key)
get in interface java.util.Map<java.lang.Long,V>public V get(long key)
Map.get(Object) that takes a primitive long key.key - for indexing the Mappublic V computeIfAbsent(long key, java.util.function.LongFunction<? extends V> mappingFunction)
LongFunction and put it in the cache.
Primitive specialized version of Map.computeIfAbsent(K, java.util.function.Function<? super K, ? extends V>).
key - to search on.mappingFunction - to provide a value if the get returns null.public V put(java.lang.Long key, V value)
put in interface java.util.Map<java.lang.Long,V>public V put(long key, V value)
Map.put(Object, Object) that takes a primitive long key.key - for indexing the Mapvalue - to be inserted in the MapMap)public V remove(java.lang.Object key)
remove in interface java.util.Map<java.lang.Long,V>public V remove(long key)
Map.remove(Object) that takes a primitive long key.key - for indexing the Mappublic void clear()
If an exception occurs during the eviction function callback then clear may need to be called again to complete.
If an exception occurs the cache should only be used when size() reports zero.
clear in interface java.util.Map<java.lang.Long,V>public void putAll(java.util.Map<? extends java.lang.Long,? extends V> map)
putAll in interface java.util.Map<java.lang.Long,V>public Long2ObjectCache.KeySet keySet()
keySet in interface java.util.Map<java.lang.Long,V>public Long2ObjectCache.ValueCollection values()
values in interface java.util.Map<java.lang.Long,V>public Long2ObjectCache.EntrySet entrySet()
entrySet in interface java.util.Map<java.lang.Long,V>public java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object o)
equals in interface java.util.Map<java.lang.Long,V>equals in class java.lang.Objectpublic int hashCode()
hashCode in interface java.util.Map<java.lang.Long,V>hashCode in class java.lang.ObjectCopyright © 2014-2019 Real Logic Ltd. All Rights Reserved.