Back to the catalog

HTTP caching from the browser to the CDN to React Query

30 questions

Follow one request outward through every cache it can hit: the browser's HTTP cache (Cache-Control, ETag, Last-Modified, revalidation), the CDN edge, the client query cache (React Query and SWR), and the server's own cache. Then tackle the hard part, invalidation. You'll meet strong and weak validators, stale-while-revalidate, cache stampedes, request coalescing, negative caching, and cache keys. Each explanation links to the RFC or docs behind the answer.

Questions

  1. Not answered. Who coined the "two hard things in Computer Science" quip?
  2. Not answered. What does Cache-Control: no-cache actually permit?
  3. Not answered. When does no-store belong on a response?
  4. Not answered. What does Cache-Control: private tell caches?
  5. Not answered. Why is the CDN serving one user's data to everyone, and what's the fix?
  6. Not answered. How long does each cache treat this response as fresh?
  7. Not answered. Which HTTP status code lets the cache reuse its copy without receiving the body again?
  8. Not answered. Which rule does a correct 304 Not Modified response follow?
  9. Not answered. When a cache revalidates a stored GET response, which headers carry which validator?
  10. Not answered. What does the W/ prefix on an ETag mean?
  11. Not answered. Why does a range request need a strong ETag, not a weak one?
  12. Not answered. Why can Last-Modified alone (with no ETag) serve an outdated body even though revalidation "succeeded"?
  13. Not answered. Which directive lets a cache return a stale response immediately while it revalidates in the background?
  14. Not answered. What does the user get 700 seconds after the response was stored?
  15. Not answered. Which directive lets a cache keep serving a stale copy when revalidation fails (the origin errors or can't be reached)?
  16. Not answered. What does adding must-revalidate to max-age=60 change in practice?
  17. Not answered. What does immutable add beyond a year-long max-age?
  18. Not answered. For how many hours will a cache treat this response as fresh?
  19. Not answered. What does Vary: Accept-Encoding tell caches to do?
  20. Not answered. What will probably happen if you add Vary: User-Agent to shared, cacheable HTML?
  21. Not answered. What does Age: 550 tell you?
  22. Not answered. Which responses should a shared CDN cache refuse to store by default?
  23. Not answered. What is the "stampede" that follows a hot key's expiry?
  24. Not answered. Which techniques actually prevent a cache stampede on a hot key?
  25. Not answered. What is this 404-caching technique called, and what is its main risk?
  26. Not answered. With request coalescing on, how many requests reach the origin?
  27. Not answered. What's the difference between staleTime and gcTime in React Query?
  28. Not answered. Why does React Query refetch data it just rendered?
  29. Not answered. What happens when two components call useSWR('/api/user') within about 2 seconds?
  30. Not answered. Why does fingerprinting make cache invalidation almost a non-problem?