KOP is a Kotlin Multiplatform object pool.
dependencies {
// ...
implementation("io.github.domgew:kop:<current_version>")
// OR just for JVM:
implementation("io.github.domgew:kop-jvm:<current_version>")
// ...
}repositories {
mavenCentral()
// ...
}See Dokka-generated docs.
typealias ObjectType = Any
suspend fun createObjectInstance(): ObjectType =
TODO()
val objectPool = KotlinObjectPool(
config = KotlinObjectPoolConfig(
maxSize = 4,
keepAliveFor = 1.minutes,
strategy = KotlinObjectPoolStrategy.LIFO,
),
// ...
) {
createObjectInstance()
}
// OR
val objectPool = KotlinObjectPool.build {
maxSize(4)
keepAliveFor(1.minutes)
strategy(KotlinObjectPoolStrategy.LIFO)
// ...
createInstance {
createObjectInstance()
}
}
suspend fun callObject() =
objectPool.withObject { instance ->
instance.call()
}Supported Targets:
- JVM
- JS: Browser
- JS: NodeJS
- wasmJS: Browser
- wasmJS: NodeJS
- Native: Android ARM64
- Native: Android ARM32
- Native: Android X64
- Native: Android X86
- Native: Linux X64
- Native: Linux ARM64
- Native: macOS X64
- Native: macOS ARM64
- Native: mingw X64
- Native: iOS X64
- Native: iOS ARM64
- Native: watchOS X64
- Native: watchOS ARM64
- Native: tvOS X64
- Native: tvOS ARM64
Kedis - Kotlin Multiplatform Redis Cache
val kedisConfiguration: KedisConfiguration = TODO()
suspend fun KedisClient.getFromCache(): String =
TODO()
val objectPool = KotlinObjectPool(
KotlinObjectPoolConfig(
maxSize = 4,
keepAliveFor = 1.minutes,
strategy = KotlinObjectPoolStrategy.LIFO,
),
) {
KedisClient(kedisConfiguration)
}
suspend fun getValueWithCache() =
objectPool.withObject { kedisClient: KedisClient ->
kedisClient.getFromCache()
}