Cache
Network Cache
A temporary store of data kept close to where it is needed — reducing fetch time by serving previously retrieved content without going back to the origin.
A cache trades storage for speed. Instead of fetching the same data repeatedly from a slow or distant source, a cache stores a copy locally and serves it on the next request. Caches exist at every layer of the internet — from CPU registers to CDN edge nodes — because the same principle applies everywhere: proximity reduces latency.
Types of cache in networking
| Cache type | Where | What it stores |
|---|---|---|
| Browser cache | Your device | Images, CSS, JS, fonts from visited sites |
| DNS cache | OS / browser | Domain-to-IP mappings (TTL-based) |
| CDN cache | Edge node | Static content from origin servers |
| Router ARP cache | Router | IP-to-MAC mappings on local network |
| Proxy cache | ISP / enterprise | Frequently requested web content |
DNS cache: OS resolver and browser
DNS resolution results are cached at multiple levels. The OS resolver cache stores recent lookups so the system does not query an upstream DNS server every time an application opens a connection. The browser maintains its own separate DNS cache on top of the OS cache — Chrome and Firefox each cache DNS results for up to 60 seconds regardless of the record's TTL. This means a DNS change can take longer to propagate to active browser sessions than the TTL suggests.
When a domain's IP address changes — for example, when migrating a site to a new server — stale cached records cause connection failures or route traffic to the old server until the cached entry expires. To force immediate resolution of the new record, flush the relevant caches:
- Windows:
ipconfig /flushdns - macOS:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder - Linux (systemd-resolved):
sudo resolvectl flush-caches - Chrome browser DNS cache: navigate to
chrome://net-internals/#dnsand click "Clear host cache"
Browser HTTP cache and Cache-Control headers
Browsers cache HTTP responses to avoid re-downloading the same assets on repeat visits. The server controls caching behaviour through the Cache-Control response header. Key directives:
max-age=N: the browser may serve this response from cache for N seconds without contacting the server.no-cache: the browser must revalidate with the server before serving from cache (sends a conditional request withIf-None-MatchorIf-Modified-Since). If the resource has not changed, the server returns 304 Not Modified and the browser uses its cached copy — saving bandwidth but not eliminating the request.no-store: the browser must not cache the response at all — every request fetches fresh from the server. Used for sensitive data like banking pages.must-revalidate: once a cached item expires (past itsmax-age), the browser must revalidate rather than serving a stale copy even when offline.
Cache-busting is a common technique for versioned static assets: by appending a content hash to filenames (e.g., app.a3f9d1.js), you ensure browsers treat an updated file as a completely new resource and never serve a stale version, while still caching unchanged files aggressively.
CDN cache: edge caching and invalidation
A CDN (Content Delivery Network) places caches at dozens to hundreds of edge locations worldwide. When a user requests a resource, the CDN edge nearest to them checks its cache. A cache hit serves the file immediately from the edge, typically in single-digit milliseconds. A cache miss causes the edge to fetch the resource from the origin server, cache it, then serve it — adding origin latency for that first request. CDN efficiency is measured as the cache hit ratio: the percentage of requests served from cache without touching the origin. Well-configured CDNs achieve 90–99% hit ratios for static content.
Cache invalidation (also called cache purge) is the process of forcing a CDN to discard cached content before its TTL expires. CDN providers expose purge APIs — you can purge by URL, by tag, or across all edges simultaneously. Purging is essential after deploying updated content that uses the same filename, or after correcting a mistake that was already cached. Without a purge, users see the old version until each edge's TTL expires.
CPU cache vs disk cache
The word "cache" also appears in hardware contexts unrelated to networking. A CPU cache (L1, L2, L3) stores frequently accessed RAM contents in fast on-chip SRAM to reduce memory access latency. A disk cache (or page cache) stores recently read or written disk blocks in RAM so subsequent accesses avoid slow I/O. These are distinct from network caches — when a support agent asks you to "clear your cache," they mean the browser HTTP cache, not CPU or disk caches.
DNS cache poisoning
DNS cache poisoning is an attack where a malicious resolver injects fraudulent DNS records into a victim resolver's cache. If successful, users querying that resolver receive a fake IP address for a legitimate domain, redirecting them to a phishing site or malicious server. The Kaminsky attack (2008) demonstrated that the birthday paradox made poisoning practical against DNS resolvers lacking source port randomisation. Modern resolvers defend against poisoning by randomising source ports and query IDs, and DNSSEC adds cryptographic signatures to DNS records so resolvers can verify authenticity.
Hard refresh and cache bypass
A normal browser reload (F5 or Ctrl+R) checks the cache and sends conditional requests, often serving cached content if it has not expired. A hard refresh (Ctrl+Shift+R on Windows/Linux, Cmd+Shift+R on macOS) forces the browser to bypass its cache entirely — every resource is re-downloaded fresh from the server regardless of cached state. This is the first debugging step when a page looks wrong after a deployment: if the hard-refreshed version is correct but the normal version is not, the issue was a stale cache.
Hard refresh bypasses the browser cache but does not flush the DNS cache or CDN cache. If a site is returning the wrong IP or serving stale content from a CDN edge, a hard refresh alone will not fix it — you need to flush the DNS cache or trigger a CDN purge respectively. This is why "clear your cache" remains step one in most web support workflows: it eliminates the browser-side cache as a variable before investigating server or CDN issues.
Frequently Asked Questions
What is a DNS cache and why does flushing it fix problems?
Your OS and browser store recent DNS lookups so they do not query a server each time. When a domain's IP changes, the stale cached record causes failures until it expires. Flush it with ipconfig /flushdns on Windows or sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder on macOS.
What is browser cache and when should I clear it?
Your browser stores copies of images, CSS, and JavaScript from visited sites for faster repeat visits. Clear it when a site looks broken or outdated — the cached version may be out of sync with the current live content. Use a hard refresh (Ctrl+Shift+R) first; a full cache clear is only needed if that does not resolve the issue.
What is a cache hit vs a cache miss?
A cache hit means data was found in the cache and served immediately — fast and cheap. A cache miss means it was not found and had to be fetched from the origin — slower and more resource-intensive. CDN performance is often measured as a cache hit ratio; the closer to 100%, the more efficiently the CDN reduces origin load and user latency.