Catalogue
The Difference Between no-cache and no-store

The Difference Between no-cache and no-store

🌐 日本語で読む

There are many cache-related directives, and among them I’ll cover no-cache and no-store, which are easy to mix up.

How no-cache Works

It does NOT mean “do not cache”!
Even when the cache is still within its expiration period, it revalidates every time to check whether the cache is up to date.

Just like Tower Records, remember it as:
No Validation, No Cache.

When to Use It

It’s effective when you want to keep up with content that changes while still taking advantage of caching.

Caveats When Using It

When the user navigates back in the browser, (disk cache) may be returned and the content may not get updated.

Reference: I investigated the issue where pressing Chrome’s Back button uses an “unintended Cache” and displays a page that differs from what you expect

Depending on the spec of the browsers you support, you may run into unintended behavior. In that case, no-store, which prevents caching altogether, is one countermeasure.

no-store

It does not store the cache and makes a request to the Origin every time.

When to Use It

As its name “no-store = do not store” suggests, you use it when you want to avoid consuming cache storage capacity.

With CDN services such as CloudFront the concern over cache storage capacity is small, but when you build a CDN yourself (DIY), storage capacity is finite, so it becomes a concern.

When You Strictly Do Not Want Caching

1
Cache-Control: private, no-store, no-cache, must-revalidate
  • private: do not cache along the path of a Proxy or CDN
  • no-store: do not store the cache
  • no-cache: do not use the cache without revalidation
  • must-revalidate: force revalidation when the cache has expired
    • do not allow stale (expired) cache to be used
    • return 504 Gateway Timeout if the Origin is down
    • cannot coexist with max-age or no-cache

Why Such Heavy Defenses

It’s to reduce compatibility issues with Proxies and CDNs.

Overall Impressions

I learned that when finely controlling cache settings, you need to take into account browser, Proxy, and CDN compatibility and carry out thorough verification.

References

A book recommended by a colleague!

It explains how to optimize and speed up delivery on the Web.

I had only used AWS CloudFront myself, but the explanation of Varnish configuration was easy to understand from the start, making it easy to get into.

My understanding of caching deepened significantly.

I’d like to take this opportunity to express my gratitude.

There’s still so much more I want to learn, such as how to run tests and how to reproduce the production environment during development.

I want a sequel!

kenzo0107

kenzo0107