Skip to content

Commit

Permalink
Debug add env var LEARNOCAML_SERVER_NOCACHE to disable all http caching
Browse files Browse the repository at this point in the history
  • Loading branch information
AltGr committed Jul 28, 2021
1 parent 2ac5c54 commit 66994f2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -57,7 +57,7 @@ testrun: build install
learn-ocaml build --repo $(REPO) -j1
rm -rf www/css
ln -s ../static/css www
learn-ocaml serve
LEARNOCAML_SERVER_NOCACHE=1 learn-ocaml serve

docker-images: Dockerfile learn-ocaml.opam
@rm -rf docker
Expand Down
9 changes: 8 additions & 1 deletion src/server/learnocaml_server.ml
Expand Up @@ -86,7 +86,14 @@ type 'a response =

type error = (Cohttp.Code.status_code * string)

let caching: type resp. resp Api.request -> caching = function
let disable_cache =
match Sys.getenv_opt "LEARNOCAML_SERVER_NOCACHE" with
| None | Some ("" | "0" | "false") -> false
| Some _ -> true

let caching: type resp. resp Api.request -> caching = fun resp ->
if disable_cache then Nocache else
match resp with
| Api.Version () -> Shortcache (Some ["version"; "server_id"])
| Api.Static ("fonts"::_ | "icons"::_ | "js"::_::_::_ as p) -> Longcache p
| Api.Static ("css"::_ | "js"::_ | _ as p) -> Shortcache (Some p)
Expand Down

0 comments on commit 66994f2

Please sign in to comment.