Package com.atlan.cache
Class AbstractOffHeapCache<K,V>
java.lang.Object
com.atlan.cache.AbstractOffHeapCache<K,V>
- All Implemented Interfaces:
AtlanCloseable
,AutoCloseable
- Direct Known Subclasses:
OffHeapAssetCache
,OffHeapFailureCache
Generic class through which to cache any key-value pairs efficiently, off-heap, to avoid
risking extreme memory usage.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Clean up the cache, once it is no longer needed.boolean
containsKey
(K key) Check whether the cache has a value in it with the provided key.protected abstract K
deserializeKey
(byte[] bytes) protected abstract V
deserializeValue
(byte[] bytes) entrySet()
Retrieve all entries held in the cache.Retrieve a value from the cache by its key.getName()
long
getSize()
Retrieve the number of entries currently held in the cache.boolean
isEmpty()
Indicates whether the cache has no entries.boolean
Indicates whether the cache has already been closed.boolean
Indicates whether the cache has any entries.void
Put a value into the cache by its key.void
putAll
(AbstractOffHeapCache<K, V> other) Put all the provided entries into the cache.protected abstract byte[]
serializeKey
(K key) protected abstract byte[]
serializeValue
(V value) long
size()
Retrieve the number of entries currently held in the cache.values()
Retrieve all the values held in the cache.
-
Constructor Details
-
AbstractOffHeapCache
Construct new object cache.- Parameters:
name
- to distinguish which cache is which
-
-
Method Details
-
serializeKey
-
deserializeKey
- Throws:
IOException
-
serializeValue
-
deserializeValue
- Throws:
IOException
-
get
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
Put a value into the cache by its key.- Parameters:
key
- of the value to put into the cachevalue
- to put into the cache
-
putAll
Put all the provided entries into the cache.- Parameters:
other
- cache of entries to add to the cache
-
containsKey
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
Retrieve all the values held in the cache.- Returns:
- a stream of all values held in the cache
-
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 interfaceAtlanCloseable
- Specified by:
close
in interfaceAutoCloseable
-
getName
-