From 7cb9c093c0ba2e18c42319f9e78d17363f6da233 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Mon, 15 Apr 2019 20:52:24 -0400 Subject: [PATCH] introduce some variation to caching to stagger refresh --- honk.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/honk.go b/honk.go index 8873440..c9b215e 100644 --- a/honk.go +++ b/honk.go @@ -29,6 +29,7 @@ import ( _ "image/png" "io" "log" + notrand "math/rand" "net/http" "os" "sort" @@ -902,10 +903,15 @@ func savehonker(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/honkers", http.StatusSeeOther) } +func somedays() string { + secs := 432000 + notrand.Int63n(432000) + return fmt.Sprintf("%d", secs) +} + func avatate(w http.ResponseWriter, r *http.Request) { n := r.FormValue("a") a := avatar(n) - w.Header().Set("Cache-Control", "max-age=432000") + w.Header().Set("Cache-Control", "max-age="+somedays()) w.Write(a) } @@ -922,7 +928,7 @@ func servehtml(w http.ResponseWriter, r *http.Request) { } func serveemu(w http.ResponseWriter, r *http.Request) { xid := mux.Vars(r)["xid"] - w.Header().Set("Cache-Control", "max-age=432000") + w.Header().Set("Cache-Control", "max-age="+somedays()) http.ServeFile(w, r, "emus/"+xid) } @@ -938,7 +944,7 @@ func servefile(w http.ResponseWriter, r *http.Request) { return } w.Header().Set("Content-Type", media) - w.Header().Set("Cache-Control", "max-age=432000") + w.Header().Set("Cache-Control", "max-age="+somedays()) w.Write(data) }