# Why Is Your CDN Cache Hit Ratio So Low?

> CDNs advertise 90%+ cache hit ratios on their webpages. So why aren't you seeing these high numbers? The reasons are complicated.

- Author: [Bhagwad Park](https://www.namehero.com/blog/author/bhagwad-park/)
- Published: 2019-05-22
- Updated: 2022-11-02
- Category: [Website Performance](https://www.namehero.com/blog/category/website-performance/)
- Web page: https://www.namehero.com/blog/why-is-your-cdn-cache-hit-ratio-so-low/

So you’ve just purchased a subscription to your shiny new CDN, and [set it up on your site](https://www.namehero.com/blog/how-to-rewrite-your-wordpress-urls-to-point-to-a-cdn/). You wait a short while and check the “hit percentage” tab on your CDN dashboard (different hosts might call it something else). And you’re disappointed to see <50% hit ratio!

Many CDN providers say that they offer as high as a 90% cache hit ratio. And for high traffic sites, it might even reach that number. But apart from a handful of providers, most people don’t see these high cache rates. In this article, I’ll explain your cache rates are probably low, and what you can do about it.

## Reason 1: Cloudflare Cache Hit Percentage is Misleading

Because Cloudflare doubles up as both a CDN and a reverse proxy server, the cache ratio calculation isn’t as simple as it would be for any other CDN provider. That’s because unlike with a regular CDN, Cloudflare also servers your dynamic content in addition to static content.

And dynamic content is *never* cached, unless you’ve set up specific page rules to that effect. And despite Cloudflare’s claim to the contrary, I [wouldn’t enable Railgun](https://www.namehero.com/blog/cloudflare-railgun-does-it-work-not-always/) if I had a choice. So when Cloudflare calculates its cache hit percentage, this is the number they’re using:

*Cached Requests/(Dynamic Requests + Static Requests)*100*

Instead, we need to subtract all the HTML requests to the server. You can find this number in the “Performance” section of the “Analytics” tab in Cloudflare as shown here:
 ![Cloudflare Dynamic HTML Requests for Cache Hit Ratio](https://www.namehero.com/blog/wp-content/uploads/2019/05/HTML-Request-Percentage-on-Cloudflare-1024x879.png)

Once you make this correction, you’ll see a much better cache hit percentage on Cloudflare!

## Reason 2: Too Many POP Servers

This might seem weird. After all, it’s a *good* thing if a CDN network has a lot of POPs right? Yes…and no. The thing is that each EDGE location requires at least one hit to cache resources. Sometimes, *more* than one hit! And when you have dozens or even hundreds of POPs, that means each has to get a request for every single static file on your site in order to cache it.

This is why cache rates take time to “build up”. For a short time, the cache hit percentage will be 0%. Then it’ll slowly start increasing as the caches fill up. But with a lot of POP servers, that build-up can take a while. Which is why you should only flush your cache rarely. A lot of work goes into “warming” it for everyone!

## Reason 3: CDN Settings like Cache Control and Cookie Caching

From a technical standpoint, your origin server should be setting the “Cache-Control” header via something like this in .htaccess:

Add cache control and stale while revalidate or error directives like this:

```
#Add cache control and stale while revalidate or error directives
  <filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
      Header set Cache-Control "max-age=2592000, stale-while-revalidate=604800, stale-if-error=604800"
  </filesMatch>
```

If not, make sure your CDN settings are configured to ignore cache-control headers.

Similarly, ensure that your CDN is stripping all cookies before caching static assets. Otherwise, each static file with a cookie will have its own cache, rendering everything useless.

## Reason 4: Infrequently Accessed Content

Despite the cache-control settings above, most CDNs will still flush out your content if it’s not being accessed frequently enough. My personal tests put this at between 2-3 days. If a file hasn’t been accessed in that time, then your CDN will toss it out of that particular EDGE server even if it’s within the “max-expires” time frame.

This why Cloudflare’s “Cache Everything” [can be detrimental to your site](https://www.namehero.com/blog/why-cloudflare-cache-everything-isnt-a-good-idea/). If you have a page that only gets a few views every week, it’s absolutely useless to cache the dynamic content. And this is why caching works best only for frequently accessed content – and best when the resources are required to be loaded for *every* page on your site.

These reasons should help you troubleshoot why you feel you might be getting a low cache hit ratio on your CDN. I hope you find this useful!

## Related posts

- [How To Achieve ~90% Cache Hit Ratio On Cloudflare](https://www.namehero.com/blog/how-to-achieve-90-cache-hit-ratio-on-cloudflare/)
- [A CDN Won’t Help Your Low Traffic Site](https://www.namehero.com/blog/a-cdn-wont-help-your-low-traffic-site/)
- [The First CDN With Infinite Cache Retention?](https://www.namehero.com/blog/the-first-cdn-with-infinite-cache-retention/)
