Package com.atlan.cache
Class OffHeapAssetCache
java.lang.Object
com.atlan.cache.OffHeapAssetCache
- All Implemented Interfaces:
Closeable
,AutoCloseable
Generic class through which to cache any assets efficiently, off-heap, to avoid risking extreme
memory usage.
-
Constructor Summary
ConstructorDescriptionOffHeapAssetCache
(AtlanClient client, String name) Construct new asset cache. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add an asset into the cache.void
close()
Clean up the cache, once it is no longer needed.boolean
containsKey
(String id) Check whether the cache has an object in it with the provided UUID.entrySet()
Retrieve all entries held in the cache.void
extendedWith
(OffHeapAssetCache other, boolean closeOriginal) Extend this cache with all the entries from the provided cache.void
extendedWith
(OffHeapAssetCache other, boolean closeOriginal, Predicate<Asset> isValid) Extend this cache with all the entries from the provided cache.Retrieve an object from the cache by its ID.getName()
long
getSize()
Retrieve the number of objects 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.protected void
Put an object into the cache by its ID.protected void
Put all the provided entries into the cache.long
size()
Retrieve the number of objects currently held in the cache.values()
Retrieve all the objects held in the cache.
-
Constructor Details
-
OffHeapAssetCache
Construct new asset cache.- Parameters:
client
- connectivity to the Atlan tenantname
- must be unique across the running code
-
-
Method Details
-
add
Add an asset into the cache. Note: the object MUST have a real (not a placeholder) UUID to be cached.- Parameters:
asset
- to add to the cache
-
extendedWith
Extend this cache with all the entries from the provided cache.- Parameters:
closeOriginal
- if true, close the provided cache after the extension is completeother
- other cache with which to extend this one- Throws:
IOException
- on any error closing the provided cache
-
extendedWith
public void extendedWith(OffHeapAssetCache other, boolean closeOriginal, Predicate<Asset> isValid) throws IOException Extend this cache with all the entries from the provided cache.- Parameters:
other
- other cache with which to extend this onecloseOriginal
- if true, close the provided cache after the extension is completeisValid
- boolean method that takes a single asset as an argument, and only when evaluated to true for an asset in the other cache will that entry from the other cache be included in this one- Throws:
IOException
- on any error closing the provided cache
-
get
Retrieve an object from the cache by its ID.- Parameters:
id
- of the object to retrieve- Returns:
- the object with that UUID, or null if it is not in the cache
-
put
Put an object into the cache by its ID.- Parameters:
id
- of the object to put into the cacheobject
- 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 an object in it with the provided UUID.- Parameters:
id
- of the object to check exists in the cache- Returns:
- true if and only if the cache has an object with this UUID in it
-
size
public long size()Retrieve the number of objects currently held in the cache.- Returns:
- the number of objects currently in the cache
-
getSize
public long getSize()Retrieve the number of objects currently held in the cache.- Returns:
- the number of objects 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 objects held in the cache.- Returns:
- a collection of all objects held in the cache
-
entrySet
Retrieve all entries held in the cache.- Returns:
- an entry set of all objects (and keys) 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
Clean up the cache, once it is no longer needed.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- if unable to remove the temporary file holding the cache
-
getName
-