Kache
2.1.2indexedLightweight caching library supports both in-memory and persistent caches with various eviction strategies (LRU, FIFO, MRU, FILO), offering coroutine-friendly operations and a simple, modern API.
Lightweight caching library supports both in-memory and persistent caches with various eviction strategies (LRU, FIFO, MRU, FILO), offering coroutine-friendly operations and a simple, modern API.
Kache is a lightweight Kotlin Multiplatform caching library that supports both in-memory and persistent caches and supports different eviction strategies (LRU, FIFO, MRU, FILO).
Supported platforms:
Kotlin DSL:
repositories {
mavenCentral()
// Add only if you're using snapshot version
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
dependencies {
// For in-memory cache
implementation("com.mayakapps.kache:kache:<version>")
// For persistent cache
implementation("com.mayakapps.kache:file-kache:<version>")
}
Groovy DSL:
repositories {
mavenCentral()
// Add only if you're using snapshot version
maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
// For in-memory cache
implementation "com.mayakapps.kache:kache:<version>"
// For persistent cache
implementation "com.mayakapps.kache:file-kache:<version>"
}
Don't forget to replace <version> with the latest found on the badges above or the desired version.
You can create your cache using the following builder DSL, then you can use the usual operators of get, put, and remove and their different implementations.
Sample Code (Kache):
// Could be InMemoryKache
val cache = Kache<String, ByteArray>(maxSize = 5 * 1024 * 1024) { // 5 MB
// Other optional configurations
strategy = KacheStrategy.LRU
}
newValue = cache.put(uniqueKey) {
{
} (ex: Throwable) {
}
}
cachedValue = cache.(uniqueKey)
Sample Code (FileKache):
// Could be OkioFileKache or JavaFileKache
val cache = FileKache(directory = "cache", maxSize = 10 * 1024 * ) {
strategy = KacheStrategy.MRU
}
{
imageData = cache.getOrPut(uniqueKey) { cacheFilename ->
{
} (ex: IOException) {
}
}
} {
cache.close()
}
See documentation here
All the code inside this library is licensed under Apache License 2.0 unless explicitly stated otherwise.
All contributions are welcome. If you are reporting an issue, please use the provided template. If you're planning to contribute to the code, please open an issue first describing what feature you're planning to add or what issue you're planning to fix. This allows better discussion and coordination of efforts. You can also check open issues for bugs/features that needs to be fixed/implemented.
Surfaced from shared tags and platforms — no rankings paid for.