cache

suspend fun <ResourceT : Any> BackendEnvironment.cache(clazz: KClass<ResourceT>, key: Any = "", factory: suspend (Configuration, Resources) -> ResourceT): ResourceT

Lazily create and memoize an object that is defined by the given class and a key.

If/when configuration or resource objects change in the environment, object is created anew. Stale copies are (eventually) deallocated.

This method is thread-safe. The same object is returned for all threads, however, when the object is being created, multiple copies might be created if there is a race condition.


suspend fun <ResourceT : Any> BackendEnvironment.Companion.cache(clazz: KClass<ResourceT>, key: Any = "", factory: suspend (Configuration, Resources) -> ResourceT): ResourceT