V
- type of values stored in the Map
public class Int2ObjectCache<V> extends Object implements Map<Integer,V>, 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 |
Int2ObjectCache.EntryIterator |
class |
Int2ObjectCache.EntrySet |
class |
Int2ObjectCache.KeyIterator |
class |
Int2ObjectCache.KeySet |
class |
Int2ObjectCache.ValueCollection |
class |
Int2ObjectCache.ValueIterator |
Constructor and Description |
---|
Int2ObjectCache(int numSets,
int setSize,
Consumer<V> evictionConsumer) |
Modifier and Type | Method and Description |
---|---|
long |
cacheHits()
The number of times a cache hit has occurred on the
get(int) method. |
long |
cacheMisses()
The number of times a cache miss has occurred on the
get(int) 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(int key,
IntFunction<? extends V> mappingFunction)
Get a value for a given key, or if it does ot exist then default the value via a
IntFunction and put it in the cache. |
boolean |
containsKey(int key)
Overloaded version of
Map.containsKey(Object) that takes a primitive int key. |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Int2ObjectCache.EntrySet |
entrySet() |
boolean |
equals(Object o) |
V |
get(int key)
Overloaded version of
Map.get(Object) that takes a primitive int key. |
V |
get(Object key) |
int |
hashCode() |
boolean |
isEmpty() |
Int2ObjectCache.KeySet |
keySet() |
V |
put(Integer key,
V value) |
V |
put(int key,
V value)
Overloaded version of
Map.put(Object, Object) that takes a primitive int key. |
void |
putAll(Map<? extends Integer,? extends V> map) |
V |
remove(int key)
Overloaded version of
Map.remove(Object) that takes a primitive int key. |
V |
remove(Object key) |
void |
resetCounters()
Reset the cache statistics counters to zero.
|
int |
size() |
String |
toString() |
Int2ObjectCache.ValueCollection |
values() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
public long cacheHits()
get(int)
method.get(int)
method.public long cacheMisses()
get(int)
method.get(int)
method.public long cachePuts()
public void resetCounters()
public int capacity()
public boolean containsKey(Object key)
containsKey
in interface Map<Integer,V>
public boolean containsKey(int key)
Map.containsKey(Object)
that takes a primitive int key.key
- for indexing the Map
public boolean containsValue(Object value)
containsValue
in interface Map<Integer,V>
public V get(int key)
Map.get(Object)
that takes a primitive int key.key
- for indexing the Map
public V computeIfAbsent(int key, IntFunction<? extends V> mappingFunction)
IntFunction
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(int key, V value)
Map.put(Object, Object)
that takes a primitive int key.public V remove(int key)
Map.remove(Object)
that takes a primitive int key.key
- for indexing the Map
public 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.
public Int2ObjectCache.KeySet keySet()
public Int2ObjectCache.ValueCollection values()
public Int2ObjectCache.EntrySet entrySet()
public boolean equals(Object o)
Copyright © 2014-2020 Real Logic Limited. All Rights Reserved.