Skip to content

Authentication and stale-while-revalidate #1228

Closed Answered by ryanflorence
Adam-Collier asked this question in Q&A
Discussion options

You must be logged in to vote

In general you don't cache responses that the user has the ability to change. In practice that's pretty much any data tied to a user. So the answer is, don't use HTTP caching for those.

HTTP caching is for public facing data that the user can't change.

General best practice is to use a server side cache (redis, memcached, etc.) and then expire those caches on mutations, or use a persistence layer that's fast already: AWS DynamoDB, Cloudflare KV/Durable Objects, Fly.io's postgres read replicas, FaunaDB, and CMS's that already built something like this into them.

To speed up authenticated UI, you can check the request.headers.get("Purpose") === "pefetch" and add a short (3 seconds?) max-age

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@mbrowne
Comment options

@sergiodxa
Comment options

@mbrowne
Comment options

Answer selected by Adam-Collier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants