K
- cache key typeV
- cache value typepublic class OHCacheBuilder<K,V> extends Object
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 MB |
chunkSize |
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 used |
fixedEntrySize |
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,
if chunkSize is also 0 |
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 fails |
false |
hashAlgorighm |
Hash algorithm to use internally. Valid options are: XX for xx-hash, MURMUR3 or CRC32
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 performace |
MURMUR3 |
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,
set segmentCount=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() and System.currentTimeMillis() |
capacity |
Expected number of elements in the cache | No default value, recommended to provide a default value. |
eviction |
Choose the eviction algorithm to use. Available are:
|
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 size |
0.2 |
You may also use system properties prefixed with org.caffinitas.org.
to other defaults.
E.g. the system property org.caffinitas.org.segmentCount
configures the default of the number of segments.
Modifier and Type | Field and Description |
---|---|
static String |
SYSTEM_PROPERTY_PREFIX |
public static final String SYSTEM_PROPERTY_PREFIX
public static <K,V> OHCacheBuilder<K,V> newBuilder()
public int getHashTableSize()
public OHCacheBuilder<K,V> hashTableSize(int hashTableSize)
public int getChunkSize()
public OHCacheBuilder<K,V> chunkSize(int chunkSize)
public long getCapacity()
public OHCacheBuilder<K,V> capacity(long capacity)
public CacheSerializer<K> getKeySerializer()
public OHCacheBuilder<K,V> keySerializer(CacheSerializer<K> keySerializer)
public CacheSerializer<V> getValueSerializer()
public OHCacheBuilder<K,V> valueSerializer(CacheSerializer<V> valueSerializer)
public int getSegmentCount()
public OHCacheBuilder<K,V> segmentCount(int segmentCount)
public float getLoadFactor()
public OHCacheBuilder<K,V> loadFactor(float loadFactor)
public long getMaxEntrySize()
public OHCacheBuilder<K,V> maxEntrySize(long maxEntrySize)
public int getFixedKeySize()
public int getFixedValueSize()
public OHCacheBuilder<K,V> fixedEntrySize(int fixedKeySize, int fixedValueSize)
public ScheduledExecutorService getExecutorService()
public OHCacheBuilder<K,V> executorService(ScheduledExecutorService executorService)
public HashAlgorithm getHashAlgorighm()
public OHCacheBuilder<K,V> hashMode(HashAlgorithm hashMode)
public boolean isThrowOOME()
public OHCacheBuilder<K,V> throwOOME(boolean throwOOME)
public boolean isUnlocked()
public OHCacheBuilder<K,V> unlocked(boolean unlocked)
public long getDefaultTTLmillis()
public OHCacheBuilder<K,V> defaultTTLmillis(long defaultTTLmillis)
public boolean isTimeouts()
public OHCacheBuilder<K,V> timeouts(boolean timeouts)
public int getTimeoutsSlots()
public OHCacheBuilder<K,V> timeoutsSlots(int timeoutsSlots)
public int getTimeoutsPrecision()
public OHCacheBuilder<K,V> timeoutsPrecision(int timeoutsPrecision)
public Ticker getTicker()
public OHCacheBuilder<K,V> ticker(Ticker ticker)
public Eviction getEviction()
public OHCacheBuilder<K,V> eviction(Eviction eviction)
public int getFrequencySketchSize()
public OHCacheBuilder<K,V> frequencySketchSize(int frequencySketchSize)
public double getEdenSize()
public OHCacheBuilder<K,V> edenSize(double edenSize)
Copyright © 2014–2017 Robert Stupp, Koeln, Germany, robert-stupp.de. All rights reserved.