Commit Diff


commit - cc18f53a514e6a399af0836b9ea3a59539228f52
commit + 35bde0c11e41be88c82553fa11d804ee9a7e0e74
blob - 5760a25e191636c36032a100e12bdaf0560cf6c5
blob + d4525a1aac064f938c573fa2a294cac44b96dfbb
--- client.go
+++ client.go
@@ -170,6 +170,11 @@ func (c *Client) Posts(community string, mode ListMode
 	defer resp.Body.Close()
 	if resp.StatusCode != http.StatusOK {
 		return nil, fmt.Errorf("remote status %s: %w", resp.Status, decodeError(resp.Body))
+	}
+	age := extractMaxAge(resp.Header)
+	ttl, err := parseMaxAge(age)
+	if c.Debug && err != nil {
+		fmt.Fprintln(os.Stderr, "parse cache max-age from header:", err)
 	}
 
 	var jresponse struct {
@@ -185,6 +190,9 @@ func (c *Client) Posts(community string, mode ListMode
 	for _, post := range jresponse.Posts {
 		post.Post.Creator = post.Creator
 		posts = append(posts, post.Post)
+		if ttl > 0 {
+			c.cache.store(post.Post, Community{}, ttl)
+		}
 	}
 	return posts, nil
 }