ContainerKache

interface ContainerKache<K : Any, C : Any>

An interface that represents a cache that holds entries within containers such as files.

The user is tasked with the serialization and deserialization of the container.

This module does not provide an implementation for this interface. An implementation can be found in the :file-kache module.

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()

Removes all keys and their corresponding containers from the cache.

Link copied to clipboard
abstract suspend fun close()

Closes the cache, releasing any resources associated with it.

Link copied to clipboard
abstract suspend fun get(key: String): C?

Returns the container 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 suspend fun getIfAvailable(key: String): C?

Returns the container corresponding to the given key, or null 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 getOrPut(key: String, creationFunction: suspend (C) -> Boolean): C?

Returns the container corresponding to the given key if it exists or is currently being created, a new container serialized 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: String, creationFunction: suspend (C) -> Boolean): C?

Associates a new container serialized by creationFunction with the given key.

Link copied to clipboard
abstract suspend fun putAsync(key: String, creationFunction: suspend (C) -> Boolean): Deferred<C?>

Associates a new container serialized by creationFunction asynchronously with the given key.

Link copied to clipboard
abstract suspend fun remove(key: String)

Removes the specified key and its corresponding container 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.