Let me start this with a screenshot of my Cloudflare dashboard showing the cache hit ratio:
I’m caching 85% of all the requests to my site WP-Tweaks. Keep in mind this includes not just legitimate traffic, but also bot traffic, spam, and even hacking attempts. The good news is that you can achieve this too. And not just with Cloudflare. NameHero allows free integration with QUIC.cloud, which can get you close to the percentage displayed above. However, QUIC.cloud is still technically in beta and doesn’t have nearly as many features as Cloudflare. So for this article, I’ll be talking about how to achieve a high cache hit ratio with Cloudflare only.
What is a Cache Hit Ratio?
The cache hit ratio is the percentage of requests that are served by the EDGE server instead of your origin. The higher this number is, the less strain on your site, and the faster your visitors see your content. This is made most clear by the reduction in the TTFB (Time To First Byte) metric. And this metric directly impacts the Core Web Vital metrics like LCP (Largest Contentful Paint).
The EDGE servers are almost always located closer to your visitors than your origin server. And the content is cached, which means it doesn’t have to be generated from scratch. Both of these combine to give blazing fast page download speeds.
This Includes Dynamic Content like HTML!
So how do we reach this super high hit percentage?
Step 1. Configuring Dynamic Content Caching
With Cloudflare, I’ve written a tutorial on how to cache dynamic content. There’s also a Cloudflare free feature for “Pro” plans and above that uses the Cloudflare plugin on your WordPress installation for HTML caching. It’s called “APO”.
For NameHero users, you can check out our knowledgebase on how to enable QUIC.cloud (Step 6). Once you have this going, you’ll immediately see a big spike in your cache hit ratio. All the bots (good and bad) will be served static HTML pages instead of getting responses from your origin. It works great!
Step 2: Enable a Good Cloud Firewall
I routinely block hundreds or even thousands of bad hits on my site using the Cloudflare WAF (Web Application Firewall). Bots probing for weaknesses should never even receive a response from your site – let alone make it through to your origin server. For Cloudflare, the WAF comes with the “Pro” plan. I prefer a cloud-based firewall to something like WordPress that runs on your server because it reduces the load on your server.
Step 3: Use Page Rules for Popular Redirects
If you’re an affiliate site, you probably have some really popular URLs that are redirected to your real affiliate link. I suggest you use Cloudflare’s Page Rules for these redirects. Not only do they keep the workload off your server, but your paying customers will also get to the destination landing page much faster. Win-win for everyone!
Step 4: Implement Sensible Rate Limiting Rules
Rate limiting is very difficult to set up correctly. But one area where you can use them safely is on your login page, where there aren’t expected to be dozens of requests every minute. I also use them on my affiliate URLs where I don’t expect an IP to be clicking many URLs in a spammy way.
Rate limiting rules have the potential to really save your site one day if it comes under heavy attack. So use them wisely!
Implementing all these techniques should easily get you in the range of 90% for your cache hit ratio. Once that happens, you’ll see all kinds of good things happen for your site. Visitors will be happier, and you’ll have fewer people accessing your site maliciously. What’s not to like?
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!