I have a `Map<FileKey, Deferred<String>&g...
# coroutines
j
I have a
Map<FileKey, Deferred<String>>
where I want to cache (expensive-to-compute) SHA-512 results. My objective is to only calculate hash values once, on the first retrieval from the Map. So I know I want some kind of Future object. I know I can start the computation in the getter (unless it's already complete) and then just return the result normally. But is Deferred the best way to do this or is there a different construct/pattern I should be looking at instead? I probably want to block on the retrieval, so Deferred may not be the best choice.
I was overthinking. Swapped to Lazy<T> instead of Deferred
j
Thanks. So the original idea is feasible. Will be worth doing for web requests but probably not local files.