The cache hit ratio is one of the metrics that measure the efficiency of content delivery networks (CDNs). CDNs use caching to store the data in edge servers, delivering it faster to users worldwide. The cache hit ratio tells us how many content requests the cache can handle effectively.
This article explains how the cache hit ratio is determined and shares some best practices to increase it.
What is a Cache Hit Ratio?
The Cache hit ratio measures how successfully a CDN serves resources stored in the cache. It’s defined as the number of cache hits divided by the total number of requests that the cache hits and misses. The result is presented in the percentage of the requests or “hits” to the applicable cache.
What’s a CDN Hit?
When the content from the cache memory is rendered successfully, it’s called “a hit”. For instance, if Chrome requests some content already located in the CDN’s cache, then the cached content delivered to the user is called a hit. If the data is missing, then it’s a miss.
What’s the Impact of “Cache Hits” and Cache “Misses” on Performance?
Your website’s performance will be impacted if the CDN has a low cache hit ratio (anything under 90%). A CDN is supposed to store all the data in a server to render it faster to users worldwide. The delivery will be much faster if the data is found in the cache memory every time.
What is a Good Cache Hit Ratio?
A high-performing CDN that provides an efficient cache policy should have a cache hit ratio (CHR) superior to 95%. A more than 90% CHR means that the cache successfully handles most requests.
On the contrary, a value below 90% (especially on static files) indicates inefficient caching and potential performance issues.
The Role of a CDN
A CDN’s performance is measured by the average memory access time. The CDN will request the origin server if the content is unavailable in the cache memory. This will result in a much longer loading time because the data requested by an international user will come from further away.
CDNs with a great cache hit ratio reduce the load on an origin server. They improve the user experience by delivering a local content copy from a closer cache edge called a Point of Presence (Pop).
|CDN with a low cache hit ratio
|CDN with a high cache hit ratio
|A cache hit ratio superior to 90% means you’ve kept requests from hitting your origin server unnecessarily.
The cache hit ratio is a key metric for a CDN, but other metrics such as RTT (round-trip time), bandwidth, and where the cached content is stored are equally important. CDNs should cache content as close to the end-user and to as many users as possible.
How to Measure the Cache Hit Ratio
Most CDNs have in-built tools that monitor key metrics such as cache hits, cache misses, and cache hit ratio. If the cache hit ratio is not displayed in the statistics of your CDN, you can try to calculate it by using the formula from the previous section.
For example, RocketCDN provides the cache hit ratio based on the following calculations:
- RocketCDN counts the number of cache hits and misses over a given period of time (= number of total requests).
- Then, it divides the cache hits by the combined number of hits and misses.
- Finally, this number is multiplied by 100 to get a percentage.
RocketCDN uses the following cache hit ratio formula = [Cache Hits / (Cache Hits + Cache Misses)] x 100
A real-life example: If you have 43 cache hits (requests) and only 2 misses, then you would divide 43 (total number of cache hits) by 45 (sum of 2 cache misses and 45 cache hits). The result would be a cache hit ratio of 0.955 or 95.5%, which is excellent.
How to Increase the Cache Hit Ratio
To increase the cache hit ratio, you can work on the size of the cache, the type of access, the frequency of the checks, and the expiry date of the cached data. There are four best practices for content delivery that you can follow to optimize your cache hit ratio:
- Specify how long the CDN should cache your data.
To increase your cache hit ratio, you can add a cache-control “max-age” on your origin server. The shorter you set the cache duration, the more often the CDN will send requests to the origin server to check if the data has changed and if it needs an update.
- Optimize your Cache-Control headers to cache static content.
The Cache-Control header specifies the instructions for the caching procedure during a request and a response. The headers have attributes that help set priorities and an expiry age for the data (time-to-leave or TTL).
If the content tends to change a lot, then you need to specify each attribute to serve the most up-to-date data to the user. Any optimizations of the attributes will increase the number of cache hits on the CDN and boost the Cache Hit Ratio.
Pro Tip: Choose a time-to-live (TTL) that matches your content. For instance, if the data changes approximately every four weeks, a cache time of fourteen days may be appropriate. On the contrary, if users access the asset daily, you may want to use a lifetime setting of one day (or even less).
Along with a CDN, you can use a cache plugin like WP Rocket that lets you control how long a visitor’s browser should cache the content on your site. You can speed up your site’s page load by caching these resources locally. You can learn more about Cache-control headers in this detailed guide written by WP Rocket.
- Ignore cookies
Cookies are usually un-cacheable, so the files that contain them also become un-cacheable. To avoid any miss hits, you must set rules such as “ignore all cookies in requests” for the data that you want to be delivered by your CDN.
- Ignore query strings to avoid any false missed hits
Query strings help interact with APIs, web applications, user information, etc. If a query string is included in static object URLs, then the CDN mistakes them as unique objects and will send the request to the origin server (instead of the edge one). Unfortunately, each request will be classified as a cache miss, even if the requested content was available in the CDN cache. This leads to an unnecessarily lower cache hit ratio.
Use RocketCDN to Ensure a High Cache Hit Ratio
RocketCDN is a powerful CDN that guarantees a Cache hit ratio of more than 95%. The CDN comes with many safety and performance features such as static asset caching, image optimization, Secure Sockets Layer (SSL), HTTP2, and even Gzip compression. For this last section, our focus will be on Rocket’s CDN caching mechanism.
Powerful caching edge servers distributed across the world
✅ Powered by Bunny CDN, RocketCDN offers more than 121 edge servers (PoPs) to ensure caching worldwide. The PoPs are highly secured servers that can render the content faster thanks to caching. The requests don’t need to go up to the origin servers making your loading time much quicker!
A Cache hit ratio > 95%
✅ RocketCDN has a Cache hit ratio superior to 95%, meaning that the cache can process many requests successfully compared to how many requests it receives.
A powerful CDN cache that never expires
✅ The cache of RocketCDN never expires, meaning that an item is stored in the CDN edge servers forever if you want to. This will also allow you to cache all the static content to avoid missed hits.
Easy set-up on WordPress
✅ RocketCDN is one of the best CDNs for WordPress sites, and it’s also compatible with every other CMS. For WordPress fervent users, you’ll find a dedicated WordPress plugin that automatically points all your assets to RocketCDN.
Is your CDN having a Cache Hit Ratio superior to 95%? Great! It means that the CDN is efficient in caching a lot of content. If that’s not the case, you should try RocketCDN as an alternative. You can try it and cancel your subscription for free up to 24 hours after your purchase. Make your website faster with a reliable cache hit ratio with RocketCDN today!