put

abstract suspend fun put(key: K, creationFunction: suspend (key: K) -> V?): V?

Creates a new entry for key using creationFunction and returns the new value. Any existing value or in-progress creation of key would be replaced by the new function. This returns null if the value cannot be created. You can imply that the creation has failed by returning null. Any unhandled exceptions inside creationFunction won't be handled.


abstract suspend fun put(key: K, value: V): V?

Caches value for key. If there is a previous value or in-progress creation, it will be replaced/cancelled. It returns the previous value if it already exists, or null if it doesn't exist or its creation is still in progress.