Package org.caffinitas.ohc
Class OHCacheBuilder<K,V>
- java.lang.Object
-
- org.caffinitas.ohc.OHCacheBuilder<K,V>
-
- Type Parameters:
K
- cache key typeV
- cache value type
public class OHCacheBuilder<K,V> extends Object
Configures and builds OHC instance.Field Meaning Default keySerializer
Serializer implementation used for keys Must be configured valueSerializer
Serializer implementation used for values Must be configured executorService
Executor service required for get operations using a cache loader. E.g. OHCache.getWithLoaderAsync(Object, CacheLoader)
(Not configured by default meaning get operations with cache loader not supported by default) segmentCount
Number of segments 2 * number of CPUs ( java.lang.Runtime.availableProcessors()
)hashTableSize
Initial size of each segment's hash table 8192
loadFactor
Hash table load factor. I.e. determines when rehashing occurs. .75f
capacity
Capacity of the cache in bytes 16 MB * number of CPUs ( java.lang.Runtime.availableProcessors()
), minimum 64 MBchunkSize
If set and positive, the chunked implementation will be used and each segment will be divided into this amount of chunks. 0
- i.e. linked implementation will be usedfixedEntrySize
If set and positive, the chunked implementation with fixed sized entries will be used. The parameter chunkSize
must be set for fixed-sized entries.0
- i.e. linked implementation will be used, ifchunkSize
is also0
maxEntrySize
Maximum size of a hash entry (including header, serialized key + serialized value) (not set, defaults to capacity divided by number of segments) throwOOME
Throw OutOfMemoryError
if off-heap allocation failsfalse
hashAlgorighm
Hash algorithm to use internally. Valid options are: XX
for xx-hash,MURMUR3
orCRC32
Note: this setting does may only help to improve throughput in rare situations - i.e. if the key is very long and you've proven that it really improves performaceMURMUR3
unlocked
If set to true
, implementations will not perform any locking. The calling code has to take care of synchronized access. In order to create an instance for a thread-per-core implementation, setsegmentCount=1
, too.false
defaultTTLmillis
If set to a value > 0
, implementations supporting TTLs will tag all entries with the given TTL in milliseconds.0
timeoutsSlots
The number of timeouts slots for each segment - compare with hashed wheel timer. 64
timeoutsPrecision
The amount of time in milliseconds for each timeouts-slot. 128
ticker
Indirection for current time - used for unit tests. Default ticker using System.nanoTime()
andSystem.currentTimeMillis()
eviction
Choose the eviction algorithm to use. Available are: LRU
: Plain LRU - least used entry is subject to evictionW-WinyLFU
: Enable use of Window Tiny-LFU. The size of the frequency sketch ("admission filter") is set to the value ofhashTableSize
. See this article for a description.None
: No entries will be evicted - this effectively provides a capacity-bounded off-heap map.
LRU
frequencySketchSize
Size of the frequency sketch used by W-WinyLFU
Defaults to hashTableSize
.edenSize
Size of the eden generation used by W-WinyLFU
relative to a segment's size0.2
You may also use system properties prefixed with
org.caffinitas.org.
to other defaults. E.g. the system propertyorg.caffinitas.org.segmentCount
configures the default of the number of segments.
-
-
Field Summary
Fields Modifier and Type Field Description static String
SYSTEM_PROPERTY_PREFIX
-
Method Summary
-
-
-
Field Detail
-
SYSTEM_PROPERTY_PREFIX
public static final String SYSTEM_PROPERTY_PREFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
newBuilder
public static <K,V> OHCacheBuilder<K,V> newBuilder()
-
getHashTableSize
public int getHashTableSize()
-
hashTableSize
public OHCacheBuilder<K,V> hashTableSize(int hashTableSize)
-
getChunkSize
public int getChunkSize()
-
chunkSize
public OHCacheBuilder<K,V> chunkSize(int chunkSize)
-
getCapacity
public long getCapacity()
-
capacity
public OHCacheBuilder<K,V> capacity(long capacity)
-
getKeySerializer
public CacheSerializer<K> getKeySerializer()
-
keySerializer
public OHCacheBuilder<K,V> keySerializer(CacheSerializer<K> keySerializer)
-
getValueSerializer
public CacheSerializer<V> getValueSerializer()
-
valueSerializer
public OHCacheBuilder<K,V> valueSerializer(CacheSerializer<V> valueSerializer)
-
getSegmentCount
public int getSegmentCount()
-
segmentCount
public OHCacheBuilder<K,V> segmentCount(int segmentCount)
-
getLoadFactor
public float getLoadFactor()
-
loadFactor
public OHCacheBuilder<K,V> loadFactor(float loadFactor)
-
getMaxEntrySize
public long getMaxEntrySize()
-
maxEntrySize
public OHCacheBuilder<K,V> maxEntrySize(long maxEntrySize)
-
getFixedKeySize
public int getFixedKeySize()
-
getFixedValueSize
public int getFixedValueSize()
-
fixedEntrySize
public OHCacheBuilder<K,V> fixedEntrySize(int fixedKeySize, int fixedValueSize)
-
getExecutorService
public ScheduledExecutorService getExecutorService()
-
executorService
public OHCacheBuilder<K,V> executorService(ScheduledExecutorService executorService)
-
getHashAlgorighm
public HashAlgorithm getHashAlgorighm()
-
hashMode
public OHCacheBuilder<K,V> hashMode(HashAlgorithm hashMode)
-
isThrowOOME
public boolean isThrowOOME()
-
throwOOME
public OHCacheBuilder<K,V> throwOOME(boolean throwOOME)
-
isUnlocked
public boolean isUnlocked()
-
unlocked
public OHCacheBuilder<K,V> unlocked(boolean unlocked)
-
getDefaultTTLmillis
public long getDefaultTTLmillis()
-
defaultTTLmillis
public OHCacheBuilder<K,V> defaultTTLmillis(long defaultTTLmillis)
-
isTimeouts
public boolean isTimeouts()
-
timeouts
public OHCacheBuilder<K,V> timeouts(boolean timeouts)
-
getTimeoutsSlots
public int getTimeoutsSlots()
-
timeoutsSlots
public OHCacheBuilder<K,V> timeoutsSlots(int timeoutsSlots)
-
getTimeoutsPrecision
public int getTimeoutsPrecision()
-
timeoutsPrecision
public OHCacheBuilder<K,V> timeoutsPrecision(int timeoutsPrecision)
-
getTicker
public Ticker getTicker()
-
ticker
public OHCacheBuilder<K,V> ticker(Ticker ticker)
-
getEviction
public Eviction getEviction()
-
eviction
public OHCacheBuilder<K,V> eviction(Eviction eviction)
-
getFrequencySketchSize
public int getFrequencySketchSize()
-
frequencySketchSize
public OHCacheBuilder<K,V> frequencySketchSize(int frequencySketchSize)
-
getEdenSize
public double getEdenSize()
-
edenSize
public OHCacheBuilder<K,V> edenSize(double edenSize)
-
-