Skip to content

Commit

Permalink
[Dashboard] Do not cache index.html to prevent issues where Dashboard…
Browse files Browse the repository at this point in the history
… doesn't load when the ray version is upgraded. (#42670)

Do not cache index.html to prevent issues where Dashboard doesn't load when the ray version is upgraded.
Explictly sets a long cache time for static files to improve performance for files we know will not change

Signed-off-by: Alan Guo <[email protected]>
  • Loading branch information
alanwguo authored Jan 26, 2024
1 parent 42deb91 commit 39f758e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion dashboard/http_server_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ async def get_index(self, req) -> aiohttp.web.FileResponse:
"This error message is harmless and can be ignored. "
f"Error: {e}"
)
return aiohttp.web.FileResponse(
resp = aiohttp.web.FileResponse(
os.path.join(
os.path.dirname(os.path.abspath(__file__)), "client/build/index.html"
)
)
resp.headers["Cache-Control"] = "no-cache"
return resp

@routes.get("/favicon.ico")
async def get_favicon(self, req) -> aiohttp.web.FileResponse:
Expand Down Expand Up @@ -190,6 +192,14 @@ async def metrics_middleware(self, request, handler):
except Exception as e:
logger.exception(f"Error emitting api metrics: {e}")

@aiohttp.web.middleware
async def cache_control_static_middleware(self, request, handler):
if request.path.startswith("/static"):
response = await handler(request)
response.headers["Cache-Control"] = "max-age=31536000"
return response
return await handler(request)

async def run(self, modules):
# Bind http routes of each module.
for c in modules:
Expand All @@ -203,6 +213,7 @@ async def run(self, modules):
self.metrics_middleware,
self.path_clean_middleware,
self.browsers_no_post_put_middleware,
self.cache_control_static_middleware,
],
)
app.add_routes(routes=routes.bound_routes())
Expand Down

0 comments on commit 39f758e

Please sign in to comment.