Web caching provides significant benefits when the requested assets are served from a nearby server. The cache hit ratio depends on the effectiveness of the caching system and is influenced by factors such as the cache policy, the number of cacheable objects, the size of the cache memory, and the expiry time of the object.
An efficient cache policy maximizes the number of cache hits while minimizing the number of cache misses, leading to a higher cache hit ratio, lower latency, and better resource utilization. A cache hit ratio of 90% and higher means that most of the requests are satisfied by the cache. A value below 80% on static files indicates inefficient caching due to poor configuration.
How to Measure Cache Hit Ratio
Most cache servers have inbuilt tools that monitor metrics such as cache hits, cache misses, and cache hit ratio. For instance, in the StackPath control panel you can easily see how your CDN cache is performing in terms of cache hits and misses. We also provide the cache hit ratio by making the following calculations:
- Determine the number of cache hits and misses over a given period of time
- Divide the cache hits by the combined number of hits and misses
- Multiply that number by 100
Cache hit ratio = [Cache Hits / (Cache Hits + Cache Misses)] x 100 %
Example of Cache Hit Ratio
Facebook users upload and view over 350 million photos per day. These photos are usually stored on Haystack machines that are optimized for photo storage. To deliver these photos, Facebook uses several photo-serving stacks with many layers of caches. In a study to determine the effectiveness of these caches, Facebook was able to determine that:
- Cache hit ratio is higher with the most popular photos.
- Cache ratio improves with larger caches. (Doubling the size of the edge cache increased the ratio from 59% to 65%. Tripling the size increased the ratio to 65%.)
- Advanced caching algorithms led to a higher cache hit ratio but at different rates. The rate increased slightly when using FIFO, LFU, and LRU, while the S4LRU algorithm (intermediate between LRU and LFU algorithms) gave the best results. S4LRU increased the ratio to up to 67.7 % and was expected to reach about 72% when the size of the edge cache was doubled.
A high cache hit ratio greatly improves the browsing experience while reducing costs in terms of energy, bandwidth, and computation power. Therefore it’s important to monitor the effectiveness of the caching system, then make adjustments to achieve a higher cache ratio.