Kotlin, Kotlin Design Patterns, Kotlin Flyweight, Kotlin Flyweight Pattern.
fetchImage(url) as well. We can fix it in multiple ways. I’ll show the way using Mutex that works similarly to the Flyweight itself: class ImageFactory { private val cache = mutableMapOf<String, Image>() private val locks = mutableMapOf<String, Mutex>() private val lock = Mutex() suspend fun