Closed matt-ramotar closed 3 months ago
We have the concept of validation. If I'm understanding correctly, you can leverage Validator.
For example, if your domain model is:
data class Item(
val id: String,
val fetchedAt: Long
)
You can create a Validator like:
private fun isWithinRange(timestamp: Long?, duration: Duration): Boolean {
if (timestamp == null) return false
val now = System.currentTimeMillis()
val durationMillis = duration.inWholeMilliseconds
return now - timestamp <= durationMillis
}
val validator = Validator.by<Item> {
isWithinRange(it.fetchedAt, 5.minutes)
}
And then add it to your Store:
val store = StoreBuilder.from<String, Item>(fetcher).validator(validator).build()
So if Validator returns true, we don't hit network. If Validator returns false, we hit network.
From https://kotlinlang.slack.com/archives/C06007Z01HU/p1717336091375779