What is the difference between res.set('Cache-Control', 'no-cache') and 'no-store' in an Express response?
Short answer
'no-cache' allows a cache to store the response, but requires it to revalidate with the origin server before reusing the cached copy on every subsequent request.
Advertisement
AModel answer
'no-cache' allows a cache to store the response, but requires it to revalidate with the origin server before reusing the cached copy on every subsequent request. 'no-store' is much stricter: it forbids storing the response at all, anywhere, appropriate for genuinely sensitive responses that must never be cached in any form.
// Allows caching but forces revalidation every time
res.set('Cache-Control', 'no-cache');
// Forbids storing this response anywhere at all
res.set('Cache-Control', 'no-store');Real-world example
A banking API sets Cache-Control: no-store on every endpoint returning account balance data, ensuring browsers, proxies, or any intermediate cache never retain a copy of that sensitive information.
Likely follow-ups
- How does a client know when a 'no-cache' response is safe to reuse versus needing to refetch it entirely?
- Why would an application choose 'no-cache' over 'no-store' when it still wants some caching-related benefit?
Related topics