commonMain.ru.casperix.multiplatform.loader.CachedResourceLoader.kt Maven / Gradle / Ivy
The newest version!
package ru.casperix.multiplatform.loader
import ru.casperix.renderer.pixel_map.PixelMap
import ru.casperix.signals.concrete.EitherFuture
abstract class CachedResourceLoader : AbstractResourceLoader {
private val bytesCache = mutableMapOf>()
private val imagesCache = mutableMapOf>()
fun clearAll() {
bytesCache.clear()
imagesCache.clear()
}
fun clear(path: String) {
bytesCache.remove(path)
imagesCache.remove(path)
}
final override fun loadBytes(path: String): EitherFuture {
return bytesCache.getOrPut(path) {
loadBytesDirect(path)
}
}
final override fun loadImage(path: String): EitherFuture {
return imagesCache.getOrPut(path) {
loadImageDirect(path)
}
}
abstract fun loadBytesDirect(path: String): EitherFuture
abstract fun loadImageDirect(path: String): EitherFuture
}