Store
A tiny Kotlin multiplatform library that assists in saving and restoring objects to and from disk using kotlinx.coroutines, kotlinx.serialisation and okio
Features
- ? Read-write locks; with a mutex FIFO lock
- ? In-memory caching; read once from disk and reuse
- ? Multiplatform!
Usage
Say you have a model
@Serializable data class Pet(val name: String, val age: Int) // Any serializable
val mylo = Pet(name = "Mylo", age = 1)
Crate a store
val storeOf: KStore<Pet> = store("whatever.json")
full confuguration here
Set value
store.set(mylo)
Get value
val mylo: Pet? = store.get()
Update a value
store.update { pet: Pet? ->
pet?.copy(age = pet.age + 1)
}
Delete/Reset value
store.delete()
You can also reset a value back to its default (if set, see here)
store.reset()
Configurations
Everything you want in the factory me
private val store: KStore<Pet> = storeOf(
path = "whatever.json", // path to file, required
default = null, // optional
enableCache = true, // optional
serializer = Json, // optional
)