The cache hit percentage is the single most important metric in representing the proper utilization and configuration of your CDN. Cache hit ratio measures the percentage of requests your CDN is able to serve from its own internal cache (Cache HIT: Client to Edge) verse requests for assets in which the CDN has to pass along a request to your Origin (Cache MISS: Client to Edge to Origin). A properly configured cache policy can provide your web app with 99.99% resource utilization, maximum speed, and minimum latency. This tutorial will further explain the Cache Hit Percentage metric and some of the factors affecting it.
What Affects CHP?
Our system honors all the cache control headers sent from the origin server, so a low cache hit percentage (CHP) means that while the static files are being served via your CDN, not all of them are being cached. The CHP calculation starts every day from 0% and builds up during the day until it reaches its maximum. With perfect CDN integration, the CHP will reach 100% every day, but there are some things that will cause the CHP to not increase:
- Purging the cache: When a Pull Zone's cache is purged, the CHP will reset to 0%.
- Not all files are cacheable: Some files might have a cache-control-header which will prevent our NginX servers from caching them. Some headers would be a "no-cache", or a very low TTL.
- New files: When new files are added to the CDN, this will affect the CHP and prevent it from reaching 100%.
- Query String: A query string is a variable that appends to a file, usually used to identify a new version of the file for the browser to recognize (for example, style.css?qstring=2). Because of this, even if the main file is cached, the query string generates a new file URL, preventing the man cached file from being served. You can correct this by disabling the query string option in Pull Zone → Advanced Features in the control panel.
- Local Caching Mechanisms: When running a caching server like Varnish, the cache control headers set by Varnish will prevent the CDN from caching the files.
Using the curl command available on Linux and Unix/OS X the results would look as follows:
# curl -I static.examplesite.net/css/style.css HTTP/1.1 200 OK Date: Mon, 27 Aug 2012 00:06:33 GMT Content-Type: text/css Connection: keep-alive Last-Modified: Fri, 24 Aug 2012 10:45:17 GMT ETag: "1f37e38-89f0-4c800abf294a8" Vary: User-Agent Expires: Tue, 28 Aug 2012 00:06:33 GMT Cache-Control: max-age=86400 Server: NetDNA-cache/2.2 X-Cache: MISS
The X-Cache: MISS indicates that the file is being pulled from the origin when requested. The same result can be achieved by using the file path in the Cache Inspector.
Resolving Low CHP
The simplest way to avoid low CHP is to avoid all the contributing factors previously mentioned. If you already have, and you are still getting a low CHP, contact our Support Team for assistance, live chat and ticket support are available 24/7.