Commit c8e853b

Eric Bower  ·  2026-04-19 23:28:07 -0400 EDT
parent 4be36ef
chore(pgs): make our cache age match our lru cache ttl
2 files changed,  +9, -3
+9, -2
......@@ -266,8 +266,15 @@ func (h *ApiAssetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
266266 }
267267 }
268268
269- // Default cache: short TTL then must revalidate using ETag
270- w.Header().Set("cache-control", "max-age=60, must-revalidate")
269+ // Default cache:
270+ // short TTL for private caches (browser),
271+ // long TTL for shared cache (our cache),
272+ // then must revalidate using ETag
273+ cc := fmt.Sprintf(
274+ "max-age=60, s-maxage=%0.f must-revalidate",
275+ h.Cfg.CacheTTL.Seconds(),
276+ )
277+ w.Header().Set("cache-control", cc)
271278
272279 for _, hdr := range userHeaders {
273280 w.Header().Add(hdr.Name, hdr.Value)
+0, -1
......@@ -733,7 +733,6 @@ func parseHeaderTime(cc string, prefix string) time.Duration {
733733 // https://www.rfc-editor.org/rfc/rfc9111#section-4.2.1
734734 func calcFreshness(state cacheControlState, expires time.Time, age time.Duration, defaultTtl time.Duration) time.Duration {
735735 ttl := defaultTtl
736- // s-maxage uses hyphen (s-maxage), max-age uses hyphen (max-age)
737736 smaxAgeDur := state.sharedMaxAge
738737 maxAgeDur := state.maxAge
739738 remExpires := time.Until(expires)