Saud Khan
06/02/2024, 1:48 PMMatthew Ramotar
06/04/2024, 1:05 PMOutput
model is:
// Domain model
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 = <http://Validator.by|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()
Matthew Ramotar
06/04/2024, 1:06 PMValidator
returns true, we don't hit network. If Validator
returns false, we hit network.Matthew Ramotar
06/04/2024, 1:11 PMSaud Khan
06/04/2024, 2:16 PM