• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • Hosting
    • Web Hosting
    • VPS Hosting
    • WordPress Hosting
    • WooCommerce Hosting
  • Reseller
  • Enterprise
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

Why Is Your CDN Cache Hit Ratio So Low?

Bhagwad Park

Published on: May 22, 2019

Categories: Website Performance 0

So you’ve just purchased a subscription to your shiny new CDN, and set it up on your site. 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 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

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. 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!

Bhagwad Park Profile Picture
Bhagwad Park

I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!

Related Posts

How To Add A “Vary: Accept-Encoding” Header To Apache

The safest value for the Vary response header is "Accept-Encoding". Here's how to easily set it in Apache without anything else.

How To Fix ERR_NAME_NOT_RESOLVED: A Quick Guide

Here's a few steps to fix ERR_NAME_NOT_RESOLVED and get back online without having to troubleshoot further.

How To Fix The “pr_connect_reset_error” Error (2023)

Pr_connect_reset_error is a common error message that occurs in network applications when a client sends a request to a server, but the server unexpectedly terminates the connection before the request is completed. This error can be caused by a variety of factors, including network connectivity issues, server configuration problems, or security issues. In this article, […]

How Can You Fix “The Response Is Not A Valid JSON Response” Error Message?

As a website owner, you can get used to site errors at some point or the other. A common issue that WordPress sites encounter is the  “The Response Is Not A Valid JSON Response.” error pop up. Sometimes a plugin conflict, or a problem with your server can cause it. But, there’s no need to […]

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!

Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup (2023)

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • Domains
Help & Support
  • NameHero Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2023 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA