@@ -23,7 +23,7 @@ import kotlin.time.Duration.Companion.hours
2323
2424fun main () {
2525 val bindingsCache =
26- Cache .Builder <ActionCoords , Map <String , Artifact >>()
26+ Cache .Builder <ActionCoords , Result < Map <String , Artifact > >>()
2727 .expireAfterAccess(1 .hours)
2828 .build()
2929
@@ -42,18 +42,17 @@ fun main() {
4242 )
4343 println (" ➡️ Requesting ${actionCoords.prettyPrint} " )
4444 val bindingArtifacts =
45- if (bindingsCache.get(actionCoords) != null ) {
46- bindingsCache.get(actionCoords)!!
47- } else {
48- val versionArtifacts = actionCoords.buildVersionArtifacts()
49- if (versionArtifacts != null ) {
50- bindingsCache.put(actionCoords, versionArtifacts)
51- versionArtifacts
52- } else {
53- call.respondText(" Not found" , status = HttpStatusCode .NotFound )
54- return @get
55- }
56- }
45+ bindingsCache.get(actionCoords) {
46+ actionCoords.buildVersionArtifacts()?.let {
47+ Result .success(it)
48+ } ? : Result .failure(object : Throwable () {})
49+ }.getOrNull()
50+
51+ if (bindingArtifacts == null ) {
52+ call.respondText(" Not found" , status = HttpStatusCode .NotFound )
53+ return @get
54+ }
55+
5756 val file = call.parameters[" file" ]!!
5857 if (file in bindingArtifacts) {
5958 when (val artifact = bindingArtifacts[file]) {
@@ -82,18 +81,16 @@ fun main() {
8281 version = version,
8382 )
8483 val bindingArtifacts =
85- if (bindingsCache.get(actionCoords) != null ) {
86- bindingsCache.get(actionCoords)!!
87- } else {
88- val versionArtifacts = actionCoords.buildVersionArtifacts()
89- if (versionArtifacts != null ) {
90- bindingsCache.put(actionCoords, versionArtifacts)
91- versionArtifacts
92- } else {
93- call.respondText(" Not found" , status = HttpStatusCode .NotFound )
94- return @head
95- }
96- }
84+ bindingsCache.get(actionCoords) {
85+ actionCoords.buildVersionArtifacts()?.let {
86+ Result .success(it)
87+ } ? : Result .failure(object : Throwable () {})
88+ }.getOrNull()
89+
90+ if (bindingArtifacts == null ) {
91+ call.respondText(" Not found" , status = HttpStatusCode .NotFound )
92+ return @head
93+ }
9794 if (file in bindingArtifacts) {
9895 call.respondText(" Exists" , status = HttpStatusCode .OK )
9996 } else {
0 commit comments