Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the same cache-control header for all non-live requests. #2064

Open
thruflo opened this issue Nov 28, 2024 · 1 comment
Open

Use the same cache-control header for all non-live requests. #2064

thruflo opened this issue Nov 28, 2024 · 1 comment

Comments

@thruflo
Copy link
Contributor

thruflo commented Nov 28, 2024

This is one suggested change partly based on the discussion in #2050.

Currently, responses to non-live requests with a -1 offset have:

cache-control: public, max-age=604800, s-maxage=3600, stale-while-revalidate=2629746

Whereas any other offset gets:

cache-control: public, max-age=60, stale-while-revalidate=300

The purpose of the lower cache duration for non -1 offsets is to enable more request-efficient data loading over time. So instead of having a long cache duration on:

insert a, b
GET offset -1 => [a, b]

insert c
GET offset 0_0 => [c]

insert d
GET offset 1234_5678 => [d]

By invalidating the cache of the second and third requests, a client coming along later will get the data in two requests:

GET offset -1 => [a, b] // still the same because cached for a longer time
GET offset 0_0 => [c, d] // compacted

This makes data loading more efficient over time for new clients. However, it also causes earlier clients to invalidate and re-fetch data that they've already synced into their private cache.

There is a solution for this and we're already using it on the -1 request: set a high max-age and / or stale-while-revalidate and a low s-maxage.

cache-control: public, max-age=604800, s-maxage=3600, stale-while-revalidate=2629746

This will allow shared (i.e.: reverse proxy / CDN) caches to revalidate and serve compacted responses after s-maxage=3600 whilst allowing private caches (browser clients) to regard the response as fresh for max-age=604800 and actually keep using whilst offline for a maximum of stale-while-revalidate=2629746.

Note lastly that this "same header for all non-live requests" is what's implemented in #2061 for 304 responses. So this suggestion also aims to standardise the cache headers between an initial 200 and subsequent 304 responses.

@thruflo
Copy link
Contributor Author

thruflo commented Nov 28, 2024

Note, please wait for @KyleAMathews to comment and approve/revise/reject the approach before implementing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant