:wave: Hi all! Say I want something like `suspend ...
# coroutines
a
👋 Hi all! Say I want something like
suspend fun request(url: URL): MyDataClass
, but I want to cache the HTTP results so I don’t make requests twice. Anyone know a good example of how to do that? @elizarov’s excellent post https://medium.com/@elizarov/deadlocks-in-non-hierarchical-csp-e5910d137cc has a nice example, but the only way I can think to wrap the channels in a suspend function is using `Deferred`’s. Is that the way to do it? It feels clunky.
w
Perhaps you could use an
actor
where the
actor
caches the results, so if it receives a message asking for
MyDataClass
it will either fetch it or used the cached version?
a
Ah yes, so this approach seems to use `Deferred`s https://github.com/kotlin/kotlinx.coroutines/blob/master/core/kotlinx-coroutines-core/test/guide/example-sync-07.kt so maybe that is the way to do it.
w
That’s probably the cleanest way.