What is caching?
DEFINITION
Caching is storing copies of data or files in a faster, closer location, such as the browser, a CDN or server memory, so repeat requests are answered without redoing the work.
A cache is a temporary store of something that was expensive to fetch or compute. When the same thing is requested again, the system serves the stored copy instead of starting from scratch. On the web, caching happens at several layers: the browser keeps images and stylesheets it has already downloaded, a CDN keeps copies at edge locations, the server can cache full pages, and applications can cache database query results in memory with tools like Redis.
Each cached item has rules about how long it stays fresh before it must be checked or refreshed.
Why caching matters
Caching is one of the most effective ways to make a site faster and cheaper to run. Returning visitors load pages almost instantly from the browser cache, and CDN and server caches mean far fewer requests reach the database.
It also improves resilience. During traffic spikes, cached pages keep the site responsive when an uncached setup might slow down or crash.
How cache headers work
Servers control browser and CDN caching with HTTP headers. Cache-Control: public, max-age=31536000, immutable tells caches that a file can be stored for a year without checking back, which is ideal for versioned assets such as styles.a81f2.css. Cache-Control: no-store prevents caching entirely, appropriate for pages with account details. A middle ground like max-age=0, must-revalidate makes the browser check with the server, using an ETag, whether its copy is still current; if so, the server replies 304 Not Modified without resending the file.
Best practices
- Use content-hashed filenames for assets so you can cache them for a long time safely.
- Set no-store or private caching for pages that show personal or account data.
- Use stale-while-revalidate to serve fast cached pages while refreshing in the background.
- Clear or purge relevant caches automatically when content is published.
Common mistakes
- Caching logged-in pages publicly so visitors see each other's information.
- Setting long cache lifetimes on unversioned files and leaving users with old versions.
- Stacking several caching plugins or layers that conflict with each other.
Frequently asked questions
What does clearing the cache do?
Clearing the browser cache deletes stored copies of files and pages, forcing the browser to download fresh versions on the next visit. On a website, purging the server or CDN cache does the same for all visitors. It is useful after updates, but well-configured caching should rarely require manual clearing.
Can caching cause problems?
Yes, if configured carelessly. Visitors may see outdated prices or content, forms may break if security tokens are cached, and personalized pages could be shown to the wrong person. Defining clear rules for what is cached, for how long and how it is invalidated prevents these issues.
What is the difference between a cache and a CDN?
A cache is any temporary store of data for faster reuse. A CDN is a network of servers around the world that, among other things, caches your files close to visitors. A CDN is one type of cache, alongside browser caches, server page caches and application caches.
Need help with this?
クラウド・DevOps by VYZEON — 自らスケールし、デプロイし、復旧するインフラを。
Fixed packages from $199. Written scope, no surprises.
