getOrLoad

open suspend override fun <V : Any> getOrLoad(key: CacheKey<V>, policy: CachePolicy, maxAge: Duration, loader: suspend () -> Result<Lookup<V>>): Result<Lookup<V>>(source)

Returns the stored answer for key if one is live and no older than maxAge; otherwise joins the load in flight for key, or starts one with loader.

Return

Result.success of the loader's Lookup; Result.failure of the loader's failure; or Result.failure of HttpFailure.Closed (component "cache") after close.

Parameters

key

the answer's identity.

policy

how long the load's outcome is stored (used only by the call that starts the load).

maxAge

the oldest stored answer this call accepts; Duration.INFINITE accepts any live entry; not negative.

loader

produces the outcome: Found/Missing are stored, a failure is not.

Throws

kotlinx.coroutines.CancellationException

if the caller is cancelled.

if the loader threw one (the same instance for every waiter).