Domains, CDN & Web Delivery

Cache Hit Ratio

Definition

Cache hit ratio is hits divided by total requests. Ninety hits and ten misses in a hundred requests is 90 percent, and the remaining ten are the ones that travelled to the origin server and back. Some providers also report a byte hit ratio, which weights by size rather than count, and the two diverge sharply when a handful of large files miss while thousands of tiny ones hit. Misses are not all failures: a cold miss is the unavoidable first request for a file in a given location, an eviction miss happens when the cache filled up and dropped something, and a configuration miss is a file that was never cacheable in the first place. That last category is the one worth hunting. For a static site of images, stylesheets, scripts and documents, anything below about 90 percent means something is wrong in the headers.

Why It Matters

The gap between 95 and 80 percent sounds small and is not. On a million requests a day, 95 percent sends 50,000 to the origin and 80 percent sends 200,000 — four times the load and four times the egress, from a change in a single header. Visitors feel it too, because a miss is a full round trip to wherever the origin lives: 30 milliseconds becomes 300 for a reader on the other side of the world. The ratio is also the fastest diagnostic you have. A site that was at 96 percent and dropped to 60 overnight has almost certainly started sending a Cache-Control value that prevents storage, or has introduced a query string that varies per visitor and splits one cached object into thousands.

How It Works

Each edge node keys its stored objects by a cache key, normally the hostname plus the path, sometimes plus selected query parameters or headers named in Vary. A request whose key is present and fresh is a hit; anything else is a miss and is fetched from the origin. Individual responses usually say which happened in a vendor header such as X-Cache: HIT or X-Cache: MISS, and an Age header shows how long the copy has been held. Three things move the number: longer freshness lifetimes set with max-age and s-maxage, a tidy cache key that strips tracking parameters like utm_source and avoids Vary on anything differing per visitor, and a shield node in front of the origin that turns dozens of cold misses into one.

Real-World Example

A publisher hosts a 30 MB sample chapter on 99helpers at draycott-books.99helpers.site ahead of a launch, and it is downloaded around 8,000 times in a week. Nearly all of those are served from nodes near the reader, so the file leaves storage a few dozen times rather than 8,000 — the difference between roughly 1 GB of origin traffic and 240 GB. The publisher manages none of it; caching headers and distribution come with the file on 99helpers. What they do see is the download count in the analytics, which counts every reader either way.

Common Mistakes

  • Reading the count-based ratio alone — a high percentage with a poor byte ratio means your large files are the ones missing, which is where the cost actually is
  • Leaving tracking parameters in the cache key — the same file arriving with fifty different utm_source values becomes fifty entries, each cold
  • Chasing 100 percent — cold misses and revalidations are normal, and a site with real content updates will never get there
  • Judging it in the first hour after a purge or a deploy — caches are empty by definition and the number climbs back over the following minutes

Related Terms

Put a file online in seconds

Drop in a document, an image, a page or a whole static website and share the link — free, with no build step and no server to set up.

Host a file free →