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) { | |
| 266 | 266 | } | |
| 267 | 267 | } | |
| 268 | 268 | ||
| 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) | |
| 271 | 278 | ||
| 272 | 279 | for _, hdr := range userHeaders { | |
| 273 | 280 | w.Header().Add(hdr.Name, hdr.Value) |
+0,
-1
| ... | ... | @@ -733,7 +733,6 @@ func parseHeaderTime(cc string, prefix string) time.Duration { | |
| 733 | 733 | // https://www.rfc-editor.org/rfc/rfc9111#section-4.2.1 | |
| 734 | 734 | func calcFreshness(state cacheControlState, expires time.Time, age time.Duration, defaultTtl time.Duration) time.Duration { | |
| 735 | 735 | ttl := defaultTtl | |
| 736 | - | // s-maxage uses hyphen (s-maxage), max-age uses hyphen (max-age) | |
| 737 | 736 | smaxAgeDur := state.sharedMaxAge | |
| 738 | 737 | maxAgeDur := state.maxAge | |
| 739 | 738 | remExpires := time.Until(expires) |