xxfast / KStore

A tiny Kotlin multiplatform library that assists in saving and restoring objects to and from disk using kotlinx.coroutines, kotlinx.serialisation and kotlinx.io
https://xxfast.github.io/KStore/
Apache License 2.0
528 stars 19 forks source link

An API to the get cached value synchronously #12

Closed xxfast closed 1 year ago

xxfast commented 1 year ago

Sometimes we want to be able to read the cached value from the store synchronously.

For example, on Ktor's default request as requested in this feature

interface Database {  
  suspend fun readUsername(): String? 
  val cachedUsername: String?
}

defaultRequest {
  database.readUsername()?.let { header("X-User-ID", it) } // wont compile
  database.cachedUsername?.let { header("X-User-ID", it) }
}
xxfast commented 1 year ago

Added in 0.3.0