From c3c240b4e6a046f6865e7c2411fea2b1bcaab980 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 21 Aug 2022 11:27:21 +0100 Subject: [PATCH] Cache the /caches.json endpoint for 15 minutes Signed-off-by: Graham --- .../kotlin/org/openrs2/archive/web/CachesController.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt b/archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt index b95971f4..c2866e3a 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt @@ -10,6 +10,7 @@ import io.ktor.http.content.caching import io.ktor.http.content.versions import io.ktor.server.application.ApplicationCall import io.ktor.server.http.content.CachingOptions +import io.ktor.server.plugins.cachingheaders.caching import io.ktor.server.response.header import io.ktor.server.response.respond import io.ktor.server.response.respondBytes @@ -54,6 +55,13 @@ public class CachesController @Inject constructor( public suspend fun indexJson(call: ApplicationCall) { val caches = exporter.list() + call.caching = CachingOptions( + cacheControl = CacheControl.MaxAge( + maxAgeSeconds = 900, + visibility = CacheControl.Visibility.Public, + ), + expires = ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(900), + ) call.respond(caches) }