repos / pico

pico services mono repo
git clone https://github.com/picosh/pico.git

commit
c8e853b
parent
4be36ef
author
Eric Bower
date
2026-04-19 23:28:07 -0400 EDT
chore(pgs): make our cache age match our lru cache ttl
2 files changed,  +9, -3
M pkg/apps/pgs/web_asset_handler.go
+9, -2
 1@@ -266,8 +266,15 @@ func (h *ApiAssetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 2 		}
 3 	}
 4 
 5-	// Default cache: short TTL then must revalidate using ETag
 6-	w.Header().Set("cache-control", "max-age=60, must-revalidate")
 7+	// Default cache:
 8+	//   short TTL for private caches (browser),
 9+	//   long TTL for shared cache (our cache),
10+	//   then must revalidate using ETag
11+	cc := fmt.Sprintf(
12+		"max-age=60, s-maxage=%0.f must-revalidate",
13+		h.Cfg.CacheTTL.Seconds(),
14+	)
15+	w.Header().Set("cache-control", cc)
16 
17 	for _, hdr := range userHeaders {
18 		w.Header().Add(hdr.Name, hdr.Value)
M pkg/httpcache/serve.go
+0, -1
1@@ -733,7 +733,6 @@ func parseHeaderTime(cc string, prefix string) time.Duration {
2 // https://www.rfc-editor.org/rfc/rfc9111#section-4.2.1
3 func calcFreshness(state cacheControlState, expires time.Time, age time.Duration, defaultTtl time.Duration) time.Duration {
4 	ttl := defaultTtl
5-	// s-maxage uses hyphen (s-maxage), max-age uses hyphen (max-age)
6 	smaxAgeDur := state.sharedMaxAge
7 	maxAgeDur := state.maxAge
8 	remExpires := time.Until(expires)