14 community map[string]entry
24 func (c *cache) store(p Post, com Community, dur time.Duration) {
27 t := time.Now().Add(dur)
28 entry := entry{expiry: t}
35 c.community[com.Name()] = entry
39 func (c *cache) delete(p Post, com Community) {
43 delete(c.community, com.Name())
47 func parseMaxAge(s string) (time.Duration, error) {
49 elems := strings.Split(s, ",")
50 for i := range elems {
51 elems[i] = strings.TrimSpace(elems[i])
52 if strings.HasPrefix(elems[i], "max-age") {
56 _, num, found := strings.Cut(want, "=")
58 return 0, fmt.Errorf("missing = separator")
60 n, err := strconv.Atoi(num)
62 return 0, fmt.Errorf("parse seconds: %w", err)
64 return time.Duration(n) * time.Second, nil
67 // Cache-Control: public, max-age=50
68 func extractMaxAge(header http.Header) string {
69 cc := header.Get("Cache-Control")
70 if !strings.Contains(cc, "max-age=") {