Skip to content

Commit dd4182e

Browse files
authored
feat(server): replace cache library with Aedile (#1835)
In order to have a better monitoring of our cache, a library that easily exposes metrics is a requirement. This commit replaces the current cache implementation with Aedile, a wrapper to Caffeine. Caffeine supports monitoring natively, while aedile allows us to access it without losing the kotlin-like style.
1 parent 126a135 commit dd4182e

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

jit-binding-server/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ dependencies {
1818
implementation("io.ktor:ktor-server-call-id")
1919
implementation("io.ktor:ktor-server-metrics-micrometer")
2020
implementation("io.micrometer:micrometer-registry-prometheus:1.14.4")
21-
22-
implementation("io.github.reactivecircus.cache4k:cache4k:0.14.0")
21+
22+
implementation("com.sksamuel.aedile:aedile-core:2.0.3")
2323
implementation("io.github.oshai:kotlin-logging:7.0.4")
2424
implementation(platform("org.apache.logging.log4j:log4j-bom:2.24.3"))
2525
implementation("org.apache.logging.log4j:log4j-jul")

jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ArtifactRoutes.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package io.github.typesafegithub.workflows.jitbindingserver
22

3+
import com.github.benmanes.caffeine.cache.Caffeine
4+
import com.sksamuel.aedile.core.asCache
5+
import com.sksamuel.aedile.core.expireAfterWrite
36
import io.github.oshai.kotlinlogging.KotlinLogging.logger
4-
import io.github.reactivecircus.cache4k.Cache
57
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
68
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.prettyPrint
79
import io.github.typesafegithub.workflows.mavenbinding.Artifact
@@ -20,16 +22,24 @@ import io.ktor.server.routing.get
2022
import io.ktor.server.routing.head
2123
import io.ktor.server.routing.route
2224
import io.micrometer.core.instrument.Tag
25+
import io.micrometer.core.instrument.binder.cache.CaffeineCacheMetrics
2326
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
2427
import kotlin.time.Duration.Companion.hours
2528

2629
private val logger = logger { }
2730

2831
typealias ArtifactResult = Result<Map<String, Artifact>>
2932

30-
private val bindingsCache = Cache.Builder<ActionCoords, ArtifactResult>().expireAfterWrite(1.hours).build()
33+
private val bindingsCache =
34+
Caffeine
35+
.newBuilder()
36+
.expireAfterWrite(1.hours)
37+
.recordStats()
38+
.asCache<ActionCoords, ArtifactResult>()
3139

3240
fun Routing.artifactRoutes(prometheusRegistry: PrometheusMeterRegistry) {
41+
CaffeineCacheMetrics.monitor(prometheusRegistry, bindingsCache.underlying(), "bindings_cache")
42+
3343
route("{owner}/{name}/{version}/{file}") {
3444
artifact(prometheusRegistry, refresh = false)
3545
}

0 commit comments

Comments
 (0)