introduce some variation to caching to stagger refresh
Ted Unangst tedu@tedunangst.com
Mon, 15 Apr 2019 20:52:24 -0400
1 files changed,
9 insertions(+),
3 deletions(-)
jump to
M
honk.go
→
honk.go
@@ -29,6 +29,7 @@ _ "image/jpeg"
_ "image/png" "io" "log" + notrand "math/rand" "net/http" "os" "sort"@@ -902,10 +903,15 @@ }
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 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 @@ http.NotFound(w, r)
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) }