Skip to content

Commit 271bc42

Browse files
authored
chore(server): use loading cache instead of normal cache (#1907)
With the loading cache you centrally define the loading strategy, which enables to later just use `get` for example, or `getAll` without having to specify the strategy in each call. It is also a requirement for using `refreshAfterWrite`.
1 parent badc797 commit 271bc42

File tree

1 file changed

+3
-3
lines changed
  • jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver

1 file changed

+3
-3
lines changed

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

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

33
import com.github.benmanes.caffeine.cache.Caffeine
4-
import com.sksamuel.aedile.core.asCache
4+
import com.sksamuel.aedile.core.asLoadingCache
55
import com.sksamuel.aedile.core.expireAfterWrite
66
import io.github.oshai.kotlinlogging.KotlinLogging.logger
77
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
@@ -35,7 +35,7 @@ private val bindingsCache =
3535
.newBuilder()
3636
.expireAfterWrite(1.hours)
3737
.recordStats()
38-
.asCache<ActionCoords, ArtifactResult>()
38+
.asLoadingCache<ActionCoords, ArtifactResult> { runCatching { it.buildVersionArtifacts()!! } }
3939

4040
fun Routing.artifactRoutes(prometheusRegistry: PrometheusMeterRegistry) {
4141
CaffeineCacheMetrics.monitor(prometheusRegistry, bindingsCache.underlying(), "bindings_cache")
@@ -105,7 +105,7 @@ private suspend fun ApplicationCall.toBindingArtifacts(refresh: Boolean): Map<St
105105
if (refresh) {
106106
bindingsCache.invalidate(actionCoords)
107107
}
108-
return bindingsCache.get(actionCoords) { runCatching { actionCoords.buildVersionArtifacts()!! } }.getOrNull()
108+
return bindingsCache.get(actionCoords).getOrNull()
109109
}
110110

111111
private fun incrementArtifactCounter(

0 commit comments

Comments
 (0)