Skip to content

Commit

Permalink
disable caching in lightly-serve (#1507)
Browse files Browse the repository at this point in the history
closes lig-4625
- disables caching for lightly-serve. This mitigates issues where the browser gets a 404 from lightly-serve due to wrong setup/configuration and caches the result even though the lightly-serve got fixed.
- also added link to the docs and added some colors (see screenshot)
  • Loading branch information
japrescott authored Feb 20, 2024
1 parent 51db826 commit 583737f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lightly/api/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ def do_OPTIONS(self) -> None:
self.send_header("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
self.end_headers()

def send_response_only(self, code, message=None):
super().send_response_only(code, message)
self.send_header(
"Cache-Control", "no-store, must-revalidate, no-cache, max-age=-1"
)
self.send_header("Expires", "0")

return HTTPServer((host, port), _LocalDatasourceRequestHandler)


Expand Down
12 changes: 10 additions & 2 deletions lightly/cli/serve_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from lightly.api import serve
from lightly.cli._helpers import fix_hydra_arguments
from lightly.utils.hipify import bcolors


@hydra.main(**fix_hydra_arguments(config_path="config", config_name="lightly-serve"))
Expand Down Expand Up @@ -39,8 +40,15 @@ def lightly_serve(cfg):
host=cfg.host,
port=cfg.port,
)
print(f"Starting server, listening at '{httpd.server_name}:{httpd.server_port}'")
print(f"Serving files in '{cfg.input_mount}' and '{cfg.lightly_mount}'")
print(
f"Starting server, listening at '{bcolors.OKBLUE}{httpd.server_name}:{httpd.server_port}{bcolors.ENDC}'"
)
print(
f"Serving files in '{bcolors.OKBLUE}{cfg.input_mount}{bcolors.ENDC}' and '{bcolors.OKBLUE}{cfg.lightly_mount}{bcolors.ENDC}'"
)
print(
f"Please follow our docs if you are facing any issues: https://docs.lightly.ai/docs/local-storage#optional-after-run-view-local-data-in-lightly-platform"
)
httpd.serve_forever()


Expand Down

0 comments on commit 583737f

Please sign in to comment.