@@ -14,6 +14,7 @@ import org.apache.pekko.actor.typed.scaladsl.AskPattern.{Askable, schedulerFromA
1414import org .apache .pekko .actor .typed .{ActorRef , ActorSystem }
1515import org .apache .pekko .http .scaladsl .model .HttpMethods ._
1616import org .apache .pekko .http .scaladsl .model .headers ._
17+ import org .apache .pekko .http .scaladsl .model .headers .CacheDirectives .{`max-age` , `must-revalidate` }
1718import org .apache .pekko .http .scaladsl .model .{ContentType , HttpEntity , HttpResponse , MediaTypes , StatusCodes , HttpHeader }
1819import org .apache .pekko .http .scaladsl .server .{Directives , ExceptionHandler , Route }
1920import org .apache .pekko .util .Timeout
@@ -42,6 +43,9 @@ class PlanRoutes(
4243
4344 // Log CORS configuration at startup
4445 UiConfiguration .Cors .logConfiguration()
46+
47+ // Cache control for static UI resources (1 day max-age with must-revalidate)
48+ private val uiCacheControl = `Cache-Control`(`max-age`(86400 ), `must-revalidate`)
4549
4650 /**
4751 * CORS configuration to allow cross-origin requests.
@@ -172,35 +176,47 @@ class PlanRoutes(
172176 lazy val planRoutes : Route = corsHandler(concat(
173177 path(" " ) {
174178 get {
175- getFromResource(" ui/index.html" )
179+ respondWithHeader(uiCacheControl) {
180+ getFromResource(" ui/index.html" )
181+ }
176182 }
177183 },
178184 path(" connection" ) {
179185 get {
180- getFromResource(" ui/connection/connection.html" )
186+ respondWithHeader(uiCacheControl) {
187+ getFromResource(" ui/connection/connection.html" )
188+ }
181189 }
182190 },
183191 path(" plan" ) {
184192 get {
185- getFromResource(" ui/plan/plan.html" )
193+ respondWithHeader(uiCacheControl) {
194+ getFromResource(" ui/plan/plan.html" )
195+ }
186196 }
187197 },
188198 path(" history" ) {
189199 get {
190- getFromResource(" ui/history/history.html" )
200+ respondWithHeader(uiCacheControl) {
201+ getFromResource(" ui/history/history.html" )
202+ }
191203 }
192204 },
193205 path(" ui" / Segments (1 , 2 )) { fileName =>
194206 val hasOnlyAlphanumericAndDash = fileName.forall(_.matches(" [0-9a-z-]+(\\ .(html|css|js))?" ))
195207 if (hasOnlyAlphanumericAndDash) {
196- getFromResource(s " ui/ ${fileName.mkString(" /" )}" )
208+ respondWithHeader(uiCacheControl) {
209+ getFromResource(s " ui/ ${fileName.mkString(" /" )}" )
210+ }
197211 } else {
198212 complete(HttpResponse (StatusCodes .BadRequest , entity = s " Unable to fetch resource for request " ))
199213 }
200214 },
201215 path(" data_catering_transparent.svg" ) {
202216 get {
203- getFromResource(" report/data_catering_transparent.svg" )
217+ respondWithHeader(uiCacheControl) {
218+ getFromResource(" report/data_catering_transparent.svg" )
219+ }
204220 }
205221 },
206222 pathPrefix(" run" ) {
0 commit comments