A tiny Kotlin multiplatform library that assists in saving and restoring objects to and from disk using kotlinx.coroutines, kotlinx.serialization and kotlinx.io. Inspired by RxStore
- 🔒 Read-write locks; with a mutex FIFO lock
- 💾 In-memory caching; read once from disk and reuse
- 📬 Default values; no file? no problem!
- 🚚 Migration support; moving shop? take your data with you
- 🚉 Multiplatform!
KStore is published on Maven Central. Latest version
repositories {
mavenCentral()
// or for snapshot builds
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
# for common
kstore = { module = "io.github.xxfast:kstore", version.ref = "kstore" }
# for android, iOS, desktop and nodeJs
kstore-file = { module = "io.github.xxfast:kstore-file", version.ref = "kstore" }
# for jsBrowser and wasmJsBrowser
kstore-storage = { module = "io.github.xxfast:kstore-storage", version.ref = "kstore" }
Depending on your target platforms, you will need to add platform configurations here
import kotlin.io.path.Path
import kotlinx.serialization.Serializable
// Take any serializable model
@Serializable data class Pet(val name: String, val age: Int)
// Create a store
val store: KStore<Pet> = storeOf(file = Path("path/to/my_cats.json"))
// Get, set, update or delete values
val mylo: Pet? = store.get()
store.set(mylo)
store.update { pet: Pet? ->
pet?.copy(age = pet.age + 1)
}
store.delete()
// Observe for updates
val pets: Flow<Pet?> = store.updates
Docume