CoroutinesCache
CoroutinesCache copied to clipboard
Inflight requests
Currently the coroutine cache isn't very smart about concurrent requests:
So if we use your readme example but modify it to perform multiple requests concurrently:
class MainActivity : AppCompatActivity() {
private val persistence by lazy { Repository(cacheDir) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
GlobalScope.launch (Dispatchers.Main) {
repeat(2) {
launch { persistence.getData().await() }
}
}
}
}
It performs the network request twice. What would actually be desired here is to have some sort of mutex so the calls will suspend so we don't request the network here twice while a request is already inflight.