OkioFileKache

A persistent coroutine-safe ContainerKache implementation that uses Okio to store files.

It uses a journal file to keep track of the cache state and to ensure that the cache is always in a consistent state.

It can be built using the following syntax:

val cache = OkioFileKache(directory = "cache".toPath(), maxSize = 100L * 1024L * 1024L) {
strategy = KacheStrategy.LRU
// ...
}

See also

Types

Link copied to clipboard
class Configuration(var directory: Path, var maxSize: Long)

Configuration for OkioFileKache used as a receiver for its builder function.

Properties

Link copied to clipboard
open override val maxSize: Long

Returns the maximum capacity of this cache in bytes.

Link copied to clipboard
open override val size: Long

Returns the current size of the cache in bytes.

Functions

Link copied to clipboard
open suspend override fun clear()

Removes all keys and their corresponding files from the cache.

Link copied to clipboard
open suspend override fun close()
Link copied to clipboard
open suspend override fun get(key: String): Path?

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

Link copied to clipboard
open suspend override fun getAllKeys(): KacheKeys<String>
Link copied to clipboard
open suspend override fun getIfAvailable(key: String): Path?

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

Link copied to clipboard
open suspend override fun getKeys(): Set<String>
Link copied to clipboard
open suspend override fun getOrPut(key: String, creationFunction: suspend (Path) -> Boolean): Path?

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

Link copied to clipboard
open suspend override fun getUnderCreationKeys(): Set<String>
Link copied to clipboard
open suspend override fun put(key: String, creationFunction: suspend (Path) -> Boolean): Path?

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

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

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

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

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

Link copied to clipboard
open suspend override fun removeAllUnderCreation()
Link copied to clipboard
open suspend override fun resize(maxSize: Long)
Link copied to clipboard
open suspend override fun trimToSize(size: Long)