Cache Hit Percentage (CHP)
The cache hit percentage (CHP) gives precise information about the amount of files served from the CDN without any requests to the origin server. In this post we will highlight what has an impact on CHP and what can be done to improve it. The cache hit ratio will only apply for Pull Zones.
The CHP is measured among all files served from a Pull Zone regardless of the file size or file type. The CHP can significantly vary depending on the environment and the setup. A typical CHP for a normal website can easily be as high as 95%.
A number of factors can influence the CHP in various ways:
- Query strings: If query strings are not ignored, each query string will create a new cache entry. This can be an important feature to distinguish different version of a file but it will cause extra cache entries if not used properly. Query strings can be ignored (see Zone settings) and regardless of the query string, it will always be cached as the same file.
- Expire headers: KeyCDN will honor all HTTP headers from the origin server (and overwrite them as defined in the Zone settings). It's important to define meaningful
- Purge: Each purge (either the entire Zone or one particular file) will delete the content on all POPs globally. The file(s) will then be cached again.
- New files: Every new file needs to be initially fetched and cached from each POP all around the world. This will result in one cache miss for each file and POP.
- User generated content (long tail content): The traffic pattern will also have a great impact on the CHP. In case of user generated content, new files need to be cached all the time (which will lead to a lower CHP).
- Not cacheable content: Not all files are cacheable. Files will only be cached based on the
Cache-Controlheader. Files with cookies will not be cached if the cookie is not stripped away (see Zone settings).
How to check a cache status
X-Cache HTTP header will indicate, if the request has been a cache hit or miss. This can easily be checked with the following curl command:
**curl -I https://website-7.kxcdn.com/img/logo.png** HTTP/1.1 200 OK Server: nginx Date: Sun, 02 Nov 2014 04:48:02 GMT Content-Type: image/png Content-Length: 6396 Connection: keep-alive Vary: Accept-Encoding Last-Modified: Sat, 26 Apr 2014 12:11:29 GMT ETag: "535ba271-18fc" Alternate-Protocol: 443:npn-spdy/3,443:npn-spdy/2 Strict-Transport-Security: max-age=31536000; includeSubdomains; preload Expires: Sun, 09 Nov 2014 04:48:02 GMT Cache-Control: max-age=604800 Link: <http://keycdn.org/img/logo.png>; rel="canonical" **X-Cache: MISS** X-Edge-Location: nlam Access-Control-Allow-Origin: * Accept-Ranges: bytes
Alternatively, the HTTP headers can also be checked online with tools like our HTTP Header Checker tool.
If the CHP is lower than expected, it's important to take a closer look and narrow down the possible root cause. In most cases it can be improved with the steps proposed above.