Class OHCacheBuilder<K,​V>

  • Type Parameters:
    K - cache key type
    V - 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 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()
    eviction Choose the eviction algorithm to use. Available are:
    • LRU: Plain LRU - least used entry is subject to eviction
    • W-WinyLFU: Enable use of Window Tiny-LFU. The size of the frequency sketch ("admission filter") is set to the value of hashTableSize. 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 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.

    • 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()
      • getCapacity

        public long getCapacity()
      • getSegmentCount

        public int getSegmentCount()
      • segmentCount

        public OHCacheBuilder<K,​V> segmentCount​(int segmentCount)
      • getLoadFactor

        public float getLoadFactor()
      • 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)
      • isThrowOOME

        public boolean isThrowOOME()
      • isUnlocked

        public boolean isUnlocked()
      • getDefaultTTLmillis

        public long getDefaultTTLmillis()
      • defaultTTLmillis

        public OHCacheBuilder<K,​V> defaultTTLmillis​(long defaultTTLmillis)
      • isTimeouts

        public boolean isTimeouts()
      • 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()
      • getEviction

        public Eviction getEviction()
      • getFrequencySketchSize

        public int getFrequencySketchSize()
      • frequencySketchSize

        public OHCacheBuilder<K,​V> frequencySketchSize​(int frequencySketchSize)
      • getEdenSize

        public double getEdenSize()