mirror of
https://github.com/InsanusMokrassar/PlaguPoster.git
synced 2025-09-15 04:59:41 +00:00
add caches
This commit is contained in:
16
common/src/commonMain/kotlin/UseCache.kt
Normal file
16
common/src/commonMain/kotlin/UseCache.kt
Normal file
@@ -0,0 +1,16 @@
|
||||
package dev.inmo.plaguposter.common
|
||||
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.module.Module
|
||||
import org.koin.core.qualifier.named
|
||||
import org.koin.core.scope.Scope
|
||||
|
||||
val Scope.useCache: Boolean
|
||||
get() = getOrNull(named("useCache")) ?: false
|
||||
|
||||
val Koin.useCache: Boolean
|
||||
get() = getOrNull(named("useCache")) ?: false
|
||||
|
||||
fun Module.useCache(useCache: Boolean) {
|
||||
single(named("useCache")) { useCache }
|
||||
}
|
@@ -10,6 +10,8 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.JsonPrimitive
|
||||
import kotlinx.serialization.json.booleanOrNull
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import org.koin.core.Koin
|
||||
import org.koin.core.module.Module
|
||||
@@ -18,6 +20,8 @@ object CommonPlugin : Plugin {
|
||||
private val Log = logger
|
||||
override fun Module.setupDI(database: Database, params: JsonObject) {
|
||||
single { CoroutineScope(Dispatchers.Default + SupervisorJob()) }
|
||||
val useCache = (params["useCache"] as? JsonPrimitive) ?.booleanOrNull ?: true
|
||||
useCache(useCache)
|
||||
}
|
||||
|
||||
override suspend fun BehaviourContext.setupBotPlugin(koin: Koin) {
|
||||
|
Reference in New Issue
Block a user