Bhandar (ভান্ডার) is a simple repository implementation that can fetch data from a fetching source and (if configured) a store for cached access.
The repository using only one model for simplicity, so the implementation on the sources would need to convert to the shared model definition.
Kotlin DSL
implementation("com.bidyut.tech.bhandar:bhandar:<version>")
Version Catalogue
[versions]
bhandar = "version"
[libraries]
bhandar = { group = "com.bidyut.tech.bhandar", name = "bhandar", version.ref = "bhandar" }
To create a new repository, we need to configure a fetcher and a storage. Let us assume a simple data model and request.
data class Request(
val id: String,
)
data class DataModel(
val id: String,
val value: String,
)
So we need a fetcher like
val fetcher = DataFetcher.of<Request, DataModel> {
// return Result.success() or Result.failure() based on the response
}
and a storage like
val storage = Storage.of<Request, DataModel>(
read = { request ->
// return flow with the data or null
},
write = { request, newValue ->
// write the data to the storage
},
)
Optionally both the fetcher and storage can have a different validation check; by default it is just non-null.