V
- type of values stored in the Map
public class Long2ObjectCache<V> extends Object implements Map<Long,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 |
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,
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,
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(Object key) |
boolean |
containsValue(Object value) |
Long2ObjectCache.EntrySet |
entrySet() |
boolean |
equals(Object o) |
V |
get(long key)
Overloaded version of
Map.get(Object) that takes a primitive long key. |
V |
get(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(Long key,
V value) |
void |
putAll(Map<? extends Long,? extends V> map) |
V |
remove(long key)
Overloaded version of
Map.remove(Object) that takes a primitive long key. |
V |
remove(Object key) |
void |
resetCounters()
Reset the cache statistics counters to zero.
|
int |
size() |
String |
toString() |
Long2ObjectCache.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(long)
method.get(long)
method.public long cacheMisses()
get(long)
method.get(long)
method.public long cachePuts()
public void resetCounters()
public int capacity()
public boolean containsKey(Object key)
containsKey
in interface Map<Long,V>
public boolean containsKey(long key)
Map.containsKey(Object)
that takes a primitive long key.key
- for indexing the Map
public boolean containsValue(Object value)
containsValue
in interface Map<Long,V>
public V get(long key)
Map.get(Object)
that takes a primitive long key.key
- for indexing the Map
public V computeIfAbsent(long key, 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(long key, V value)
Map.put(Object, Object)
that takes a primitive long key.public V remove(long key)
Map.remove(Object)
that takes a primitive long 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 Long2ObjectCache.KeySet keySet()
public Long2ObjectCache.ValueCollection values()
public Long2ObjectCache.EntrySet entrySet()
public boolean equals(Object o)
Copyright © 2014-2020 Real Logic Limited. All Rights Reserved.