Skip to content

Commit 3c10dd7

Browse files
committed
Use Optional
1 parent 3a2e0c9 commit 3c10dd7

File tree

3 files changed

+7
-29
lines changed

3 files changed

+7
-29
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
2525
import kotlinx.coroutines.CoroutineScope
2626
import kotlinx.coroutines.Dispatchers
2727
import kotlinx.coroutines.launch
28+
import java.util.Optional
29+
import kotlin.jvm.optionals.getOrNull
2830

2931
private val logger = logger { }
3032

33+
typealias CachedVersionArtifact = Optional<VersionArtifacts>
34+
3135
private val prefetchScope = CoroutineScope(Dispatchers.IO)
3236

3337
fun Routing.artifactRoutes(
@@ -118,7 +122,7 @@ private suspend fun ApplicationCall.toBindingArtifacts(
118122
if (refresh) {
119123
bindingsCache.invalidate(actionCoords)
120124
}
121-
return bindingsCache.get(actionCoords).toNullableVersionArtifacts()
125+
return bindingsCache.get(actionCoords).getOrNull()
122126
}
123127

124128
private fun PrometheusMeterRegistry.incrementArtifactCounter(

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

Lines changed: 0 additions & 27 deletions
This file was deleted.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import io.micrometer.core.instrument.Tag
2626
import io.micrometer.prometheusmetrics.PrometheusConfig
2727
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
2828
import java.time.Duration
29+
import java.util.Optional
2930
import kotlin.time.Duration.Companion.hours
3031

3132
private val logger =
@@ -109,7 +110,7 @@ private fun buildBindingsCache(
109110
.newBuilder()
110111
.refreshAfterWrite(1.hours)
111112
.recordStats()
112-
.asLoadingCache { buildVersionArtifacts(it, httpClient).toCachedVersionArtifact() }
113+
.asLoadingCache { Optional.ofNullable(buildVersionArtifacts(it, httpClient)) }
113114

114115
@Suppress("ktlint:standard:function-signature") // Conflict with detekt.
115116
private fun buildMetadataCache(

0 commit comments

Comments
 (0)