Class AbstractOffHeapCache<K,V>

java.lang.Object
com.atlan.cache.AbstractOffHeapCache<K,V>
All Implemented Interfaces:
AtlanCloseable, AutoCloseable
Direct Known Subclasses:
OffHeapAssetCache, OffHeapFailureCache

public abstract class AbstractOffHeapCache<K,V> extends Object implements AtlanCloseable
Generic class through which to cache any key-value pairs efficiently, off-heap, to avoid risking extreme memory usage.
  • Constructor Details

    • AbstractOffHeapCache

      public AbstractOffHeapCache(String name)
      Construct new object cache.
      Parameters:
      name - to distinguish which cache is which
  • Method Details

    • serializeKey

      protected abstract byte[] serializeKey(K key)
    • deserializeKey

      protected abstract K deserializeKey(byte[] bytes) throws IOException
      Throws:
      IOException
    • serializeValue

      protected abstract byte[] serializeValue(V value)
    • deserializeValue

      protected abstract V deserializeValue(byte[] bytes) throws IOException
      Throws:
      IOException
    • get

      public V get(K key)
      Retrieve a value from the cache by its key.
      Parameters:
      key - of the value to retrieve
      Returns:
      the value with that key, or null if it is not in the cache
    • put

      public void put(K key, V value)
      Put a value into the cache by its key.
      Parameters:
      key - of the value to put into the cache
      value - to put into the cache
    • putAll

      public void putAll(AbstractOffHeapCache<K,V> other)
      Put all the provided entries into the cache.
      Parameters:
      other - cache of entries to add to the cache
    • containsKey

      public boolean containsKey(K key)
      Check whether the cache has a value in it with the provided key.
      Parameters:
      key - of the value to check exists in the cache
      Returns:
      true if and only if the cache has a value with this key in it
    • size

      public long size()
      Retrieve the number of entries currently held in the cache.
      Returns:
      the number of entries currently in the cache
    • getSize

      public long getSize()
      Retrieve the number of entries currently held in the cache.
      Returns:
      the number of entries currently in the cache
    • isEmpty

      public boolean isEmpty()
      Indicates whether the cache has no entries.
      Returns:
      true if the cache has no entries, otherwise false
    • isNotEmpty

      public boolean isNotEmpty()
      Indicates whether the cache has any entries.
      Returns:
      true if the cache has at least one entry, otherwise false
    • values

      public Stream<V> values()
      Retrieve all the values held in the cache.
      Returns:
      a stream of all values held in the cache
    • entrySet

      public Stream<Map.Entry<K,V>> entrySet()
      Retrieve all entries held in the cache.
      Returns:
      an entry set of all keys (and their values) held in the cache
    • isNotClosed

      public boolean isNotClosed()
      Indicates whether the cache has already been closed.
      Returns:
      true if the cache has been closed, otherwise false
    • close

      public void close()
      Clean up the cache, once it is no longer needed.
      Specified by:
      close in interface AtlanCloseable
      Specified by:
      close in interface AutoCloseable
    • getName

      public String getName()