Skip to content

Commit

Permalink
feat: switch cache type based on config
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiinaKin committed Sep 13, 2024
1 parent c8c41c8 commit d1e0d2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
20 changes: 11 additions & 9 deletions app/src/main/kotlin/io/sakurasou/plugins/Cache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.sakurasou.plugins

import com.ucasoft.ktor.simpleCache.SimpleCache
import com.ucasoft.ktor.simpleMemoryCache.memoryCache
import com.ucasoft.ktor.simpleRedisCache.redisCache
import io.ktor.server.application.*
import kotlin.time.Duration.Companion.seconds

Expand All @@ -11,15 +12,16 @@ import kotlin.time.Duration.Companion.seconds
*/
fun Application.configureCache(host: String, port: String) {
install(SimpleCache) {
memoryCache {
invalidateAt = 10.seconds
if (host != "disabled") {
redisCache {
invalidateAt = 10.seconds
this.host = host
this.port = port.toInt()
}
} else {
memoryCache {
invalidateAt = 10.seconds
}
}
}
// install(SimpleCache) {
// redisCache {
// invalidateAt = 10.seconds
// host = "localhost"
// port = 6379
// }
// }
}
4 changes: 2 additions & 2 deletions app/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ ktor:
password: $DATABASE_PASSWORD
cache:
redis:
host: $REDIS_HOST
port: $REDIS_PORT
host: "$REDIS_HOST:disable"
port: "$REDIS_PORT:6379"
deployment:
port: 8080
watch:
Expand Down

0 comments on commit d1e0d2f

Please sign in to comment.