Class OHCacheChunkedImpl<K,​V>

    • Constructor Detail

      • OHCacheChunkedImpl

        public OHCacheChunkedImpl​(OHCacheBuilder<K,​V> builder)
    • Method Detail

      • getDirect

        public DirectValueAccess getDirect​(K key)
        Description copied from interface: OHCache
        Returns a closeable byte buffer. You must close the returned DirectValueAccess instance after use. After closing, you must not call any of the methods of the ByteBuffer returned by DirectValueAccess.buffer().
        Specified by:
        getDirect in interface OHCache<K,​V>
        Parameters:
        key - the key of the value to retrieve
        Returns:
        reference-counted byte buffer or null if key does not exist.
      • getDirect

        public DirectValueAccess getDirect​(K key,
                                           boolean updateLRU)
        Description copied from interface: OHCache
        Like OHCache.getDirect(Object), but allows skipping the update of LRU stats when updateLRU is false.
        Specified by:
        getDirect in interface OHCache<K,​V>
        Parameters:
        key - the key to retrieve
        updateLRU - whether to update LRU stats
        Returns:
        reference-counted byte buffer or null if key does not exist.
      • get

        public V get​(K key)
        Description copied from interface: OHCache
        Get the value for a given key.
        Specified by:
        get in interface OHCache<K,​V>
        Parameters:
        key - key of the entry to be retrieved. Must not be null.
        Returns:
        either the non-null value or null if no entry for the requested key exists
      • containsKey

        public boolean containsKey​(K key)
        Description copied from interface: OHCache
        Checks whether an entry for a given key exists. Usually, this is more efficient than testing for null via OHCache.get(Object).
        Specified by:
        containsKey in interface OHCache<K,​V>
        Parameters:
        key - key of the entry to be retrieved. Must not be null.
        Returns:
        either true if an entry for the given key exists or false if no entry for the requested key exists
      • put

        public boolean put​(K key,
                           V value)
        Description copied from interface: OHCache
        Same as OHCache.put(Object, Object, long) but uses the configured default TTL, if any.
        Specified by:
        put in interface OHCache<K,​V>
        Parameters:
        key - key of the entry to be added. Must not be null.
        value - value of the entry to be added. Must not be null.
        Returns:
        true, if the entry has been added, false otherwise
      • put

        public boolean put​(K key,
                           V value,
                           long expireAt)
        Description copied from interface: OHCache
        Adds the key/value. If the entry size of key/value exceeds the configured maximum entry length, any previously existing entry for the key is removed.
        Specified by:
        put in interface OHCache<K,​V>
        Parameters:
        key - key of the entry to be added. Must not be null.
        value - value of the entry to be added. Must not be null.
        expireAt - timestamp in milliseconds since "epoch" (like System.currentTimeMillis()) when the entry shall expire. Pass OHCache.USE_DEFAULT_EXPIRE_AT for the configured default time-to-live or OHCache.NEVER_EXPIRE to let it never expire.
        Returns:
        true, if the entry has been added, false otherwise
      • addOrReplace

        public boolean addOrReplace​(K key,
                                    V old,
                                    V value)
        Description copied from interface: OHCache
        Same as OHCache.addOrReplace(Object, Object, Object, long) but uses the configured default TTL, if any.
        Specified by:
        addOrReplace in interface OHCache<K,​V>
        Parameters:
        key - key of the entry to be added or replaced. Must not be null.
        old - if the entry exists, it's serialized value is compared to the serialized value of old and only replaced, if it matches.
        value - value of the entry to be added. Must not be null.
        Returns:
        true on success or false if the existing value does not matcuh old
      • addOrReplace

        public boolean addOrReplace​(K key,
                                    V old,
                                    V value,
                                    long expireAt)
        Description copied from interface: OHCache
        Adds key/value if either the key is not present or the existing value matches parameter old. If the entry size of key/value exceeds the configured maximum entry length, the old value is removed.
        Specified by:
        addOrReplace in interface OHCache<K,​V>
        Parameters:
        key - key of the entry to be added or replaced. Must not be null.
        old - if the entry exists, it's serialized value is compared to the serialized value of old and only replaced, if it matches.
        value - value of the entry to be added. Must not be null.
        expireAt - timestamp in milliseconds since "epoch" (like System.currentTimeMillis()) when the entry shall expire. Pass OHCache.USE_DEFAULT_EXPIRE_AT for the configured default time-to-live or OHCache.NEVER_EXPIRE to let it never expire.
        Returns:
        true on success or false if the existing value does not matcuh old
      • putIfAbsent

        public boolean putIfAbsent​(K key,
                                   V value)
        Description copied from interface: OHCache
        Same as OHCache.putIfAbsent(Object, Object, long) but uses the configured default TTL, if any.
        Specified by:
        putIfAbsent in interface OHCache<K,​V>
        Parameters:
        key - key of the entry to be added. Must not be null.
        value - value of the entry to be added. Must not be null.
        Returns:
        true on success or false if the key is already present.
      • putIfAbsent

        public boolean putIfAbsent​(K key,
                                   V value,
                                   long expireAt)
        Description copied from interface: OHCache
        Adds the key/value if the key is not present. If the entry size of key/value exceeds the configured maximum entry length, any previously existing entry for the key is removed.
        Specified by:
        putIfAbsent in interface OHCache<K,​V>
        Parameters:
        key - key of the entry to be added. Must not be null.
        value - value of the entry to be added. Must not be null.
        expireAt - timestamp in milliseconds since "epoch" (like System.currentTimeMillis()) when the entry shall expire. Pass OHCache.USE_DEFAULT_EXPIRE_AT for the configured default time-to-live or OHCache.NEVER_EXPIRE to let it never expire.
        Returns:
        true on success or false if the key is already present.
      • remove

        public boolean remove​(K k)
        Description copied from interface: OHCache
        Remove a single entry for the given key.
        Specified by:
        remove in interface OHCache<K,​V>
        Parameters:
        k - key of the entry to be removed. Must not be null.
        Returns:
        true, if the entry has been removed, false otherwise
      • getWithLoaderAsync

        public Future<V> getWithLoaderAsync​(K key,
                                            CacheLoader<K,​V> loader)
        Description copied from interface: OHCache
        Shortcut to call OHCache.getWithLoader(Object, CacheLoader, long, TimeUnit) using the default entry time-to-live. Note that the cache has to be configured with an Executor to schedule the load process.

        Note that the future may indicate a failure via it's get methods if the CacheLoader.load(Object) implementation threw an error or a runtime exception occured due to not enough memory for example.

        Specified by:
        getWithLoaderAsync in interface OHCache<K,​V>
        Parameters:
        key - key of the value to load
        loader - loader implementation to use
        Returns:
        a future to process the load request asynchronously.
      • getWithLoaderAsync

        public Future<V> getWithLoaderAsync​(K key,
                                            CacheLoader<K,​V> loader,
                                            long expireAt)
        Description copied from interface: OHCache
        Shortcut to call OHCache.getWithLoader(Object, CacheLoader, long, TimeUnit) using the default entry time-to-live. Note that the cache has to be configured with an Executor to schedule the load process.

        Note that the future may indicate a failure via it's get methods if the CacheLoader.load(Object) implementation threw an error or a runtime exception occured due to not enough memory for example.

        Specified by:
        getWithLoaderAsync in interface OHCache<K,​V>
        Parameters:
        key - key of the value to load
        loader - loader implementation to use
        expireAt - optional timestamp (millis since epoch) at which the entry shall expire
        Returns:
        a future to process the load request asynchronously.
      • clear

        public void clear()
        Description copied from interface: OHCache
        Removes all entries from the cache.
        Specified by:
        clear in interface OHCache<K,​V>
      • setCapacity

        public void setCapacity​(long capacity)
        Description copied from interface: OHCache
        Modify the cache's capacity. Lowering the capacity will not immediately remove any entry nor will it immediately free allocated (off heap) memory.

        Future operations will even allocate in flight, temporary memory - i.e. setting capacity to 0 does not disable the cache, it will continue to work but cannot add more data.

        Specified by:
        setCapacity in interface OHCache<K,​V>
        Parameters:
        capacity - the new capacity
      • capacity

        public long capacity()
        Specified by:
        capacity in interface OHCache<K,​V>
      • size

        public long size()
        Specified by:
        size in interface OHCache<K,​V>
      • segments

        public int segments()
        Specified by:
        segments in interface OHCache<K,​V>
      • loadFactor

        public float loadFactor()
        Specified by:
        loadFactor in interface OHCache<K,​V>
      • deserializeEntry

        public boolean deserializeEntry​(ReadableByteChannel channel)
        Description copied from interface: OHCache
        Deserialize a single entry.
        Specified by:
        deserializeEntry in interface OHCache<K,​V>
        Parameters:
        channel - channel to read from
        Returns:
        whether the deserialization was successful
      • serializeEntry

        public boolean serializeEntry​(K key,
                                      WritableByteChannel channel)
        Description copied from interface: OHCache
        Serialize a cache entry.
        Specified by:
        serializeEntry in interface OHCache<K,​V>
        Parameters:
        key - Key of the cache entry to serialize
        channel - target channel to write to
        Returns:
        whether the serialization was successful
      • deserializeEntries

        public int deserializeEntries​(ReadableByteChannel channel)
        Description copied from interface: OHCache
        Deserialize entries.
        Specified by:
        deserializeEntries in interface OHCache<K,​V>
        Parameters:
        channel - channel to read from
        Returns:
        number of deserialized entries
      • serializeHotNEntries

        public int serializeHotNEntries​(int n,
                                        WritableByteChannel channel)
        Description copied from interface: OHCache
        Serialize a the hottest cache entries.
        Specified by:
        serializeHotNEntries in interface OHCache<K,​V>
        Parameters:
        n - number of cache entries to serialize
        channel - target channel to write to
        Returns:
        number of serialized entries
      • serializeHotNKeys

        public int serializeHotNKeys​(int n,
                                     WritableByteChannel channel)
        Description copied from interface: OHCache
        Serialize a the keys of the hottest cache entries.
        Specified by:
        serializeHotNKeys in interface OHCache<K,​V>
        Parameters:
        n - number of cache entries to serialize
        channel - target channel to write to
        Returns:
        number of serialized entries
      • putAll

        public void putAll​(Map<? extends K,​? extends V> m)
        Description copied from interface: OHCache
        This is effectively a shortcut to add all entries in the given map m.
        Specified by:
        putAll in interface OHCache<K,​V>
        Parameters:
        m - entries to be added
      • removeAll

        public void removeAll​(Iterable<K> iterable)
        Description copied from interface: OHCache
        This is effectively a shortcut to remove the entries for all keys given in the iterable keys.
        Specified by:
        removeAll in interface OHCache<K,​V>
        Parameters:
        iterable - keys to be removed
      • memUsed

        public long memUsed()
        Specified by:
        memUsed in interface OHCache<K,​V>
      • hotKeyIterator

        public CloseableIterator<K> hotKeyIterator​(int n)
        Description copied from interface: OHCache
        Builds an iterator over the N most recently used keys returning deserialized objects. You must call close() on the returned iterator.

        Note: During a rehash, the implementation might return keys twice or not at all.

        Specified by:
        hotKeyIterator in interface OHCache<K,​V>
        Parameters:
        n - the N most recently used keys
        Returns:
        closeable iterator over the keys
      • hotKeyBufferIterator

        public CloseableIterator<ByteBuffer> hotKeyBufferIterator​(int n)
        Description copied from interface: OHCache
        Builds an iterator over all keys returning direct byte buffers. Do not use a returned ByteBuffer after calling any method on the iterator. You must call close() on the returned iterator.

        Note: During a rehash, the implementation might return keys twice or not at all.

        Specified by:
        hotKeyBufferIterator in interface OHCache<K,​V>
        Parameters:
        n - the N most recently used keys
        Returns:
        closeable iterator over byte-buffers
      • keyIterator

        public CloseableIterator<K> keyIterator()
        Description copied from interface: OHCache
        Builds an iterator over all keys returning deserialized objects. You must call close() on the returned iterator.

        Note: During a rehash, the implementation might return keys twice or not at all.

        Specified by:
        keyIterator in interface OHCache<K,​V>
        Returns:
        closeable iterator over the keys
      • keyBufferIterator

        public CloseableIterator<ByteBuffer> keyBufferIterator()
        Description copied from interface: OHCache
        Builds an iterator over all keys returning direct byte buffers. Do not use a returned ByteBuffer after calling any method on the iterator. You must call close() on the returned iterator.

        Note: During a rehash, the implementation might return keys twice or not at all.

        Specified by:
        keyBufferIterator in interface OHCache<K,​V>
        Returns:
        closeable iterator over byte-buffers