ocaml http/1, http/2 and websocket client and server library
at main 646 B view raw
1let cached_date = Atomic.make "" 2let cached_time = Atomic.make 0. 3 4let format_date () = 5 let t = Unix.gettimeofday () in 6 let tm = Unix.gmtime t in 7 Buf.build64 (fun b -> 8 Buf.http_date b ~wday:tm.Unix.tm_wday ~mday:tm.Unix.tm_mday 9 ~mon:tm.Unix.tm_mon ~year:(1900 + tm.Unix.tm_year) ~hour:tm.Unix.tm_hour 10 ~min:tm.Unix.tm_min ~sec:tm.Unix.tm_sec) 11 12let[@inline] get () = 13 let now = Unix.gettimeofday () in 14 let last = Atomic.get cached_time in 15 if now -. last >= 1.0 then begin 16 let date = format_date () in 17 Atomic.set cached_date date; 18 Atomic.set cached_time now; 19 date 20 end 21 else Atomic.get cached_date