ObjectKache

interface ObjectKache<K : Any, V : Any>

An interface that represents a cache that holds entries in memory without serialization.

Inheritors

Properties

Link copied to clipboard
abstract val maxSize: Long

Returns the maximum capacity of this cache, defined by the implementation.

Link copied to clipboard
abstract val size: Long

Returns the current size of the cache, defined by the implementation.

Functions

Link copied to clipboard
abstract suspend fun clear()

Clears the cache, calling EntryRemovedListener on each removed entry with evicted set to false.

Link copied to clipboard
abstract suspend fun evictAll()

Removes all keys and their corresponding values from the cache.

Link copied to clipboard
abstract suspend fun evictExpired()

Removes all expired keys and their corresponding values from the cache.

Link copied to clipboard
abstract suspend fun get(key: K): V?

Returns the value corresponding to the given key if it exists or is currently being created, or null otherwise.

Link copied to clipboard
abstract suspend fun getAllKeys(): KacheKeys<K>

Returns a KacheKeys object containing all keys in the cache, including under-creation keys.

Link copied to clipboard
abstract fun getIfAvailable(key: K): V?

Returns the value corresponding to the given key, or null if such a key is not present in the cache.

Link copied to clipboard
abstract fun getIfAvailableOrDefault(key: K, defaultValue: V): V

Returns the value corresponding to the given key, or defaultValue if such a key is not present in the cache.

Link copied to clipboard
abstract suspend fun getKeys(): Set<K>

Returns a read-only Set of keys currently in the cache, excluding under-creation keys.

Link copied to clipboard
abstract suspend fun getOrDefault(key: K, defaultValue: V): V

Returns the value corresponding to the given key if it exists or is currently being created, or defaultValue otherwise.

Link copied to clipboard
abstract suspend fun getOrPut(key: K, creationFunction: suspend (key: K) -> V?): V?

Returns the value corresponding to the given key if it exists, is currently being created, a new value created by creationFunction, or null if the creation fails.

Link copied to clipboard
abstract suspend fun getUnderCreationKeys(): Set<K>

Returns a read-only Set of keys currently under creation.

Link copied to clipboard
abstract suspend fun put(key: K, value: V): V?

Associates the specified value with the specified key in the cache.

abstract suspend fun put(key: K, creationFunction: suspend (key: K) -> V?): V?

Associates a new value created by creationFunction with the given key.

Link copied to clipboard
abstract suspend fun putAll(from: Map<out K, V>)

Updates this cache with key/value pairs from the specified map from.

Link copied to clipboard
abstract suspend fun putAsync(key: K, creationFunction: suspend (key: K) -> V?): Deferred<V?>

Associates a new value created by creationFunction asynchronously with the given key.

Link copied to clipboard
abstract suspend fun remove(key: K): V?

Removes the specified key and its corresponding value from the cache.

Link copied to clipboard
abstract suspend fun removeAllUnderCreation()

Cancels all in-progress creations.

Link copied to clipboard
abstract suspend fun resize(maxSize: Long)

Sets the maximum capacity of this cache to maxSize.

Link copied to clipboard
abstract suspend fun trimToSize(size: Long)

Remove entries from the cache until the size is less than or equal to size.