In mobile development exists solution for caching with RxJava usage, but there is no solutions for Kotlin Coroutines. The project is to provide this functionality to mobile community.
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.
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:
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.