KeyCDN Launches Country Based Caching
KeyCDN supports now country code based caching of your assets. Our edge servers derive the two-letter country code from the client IP address, that code is used for the cache key and forwarded to the origin server. Each time the client comes from a different country creates a dedicated cache entry.
Why is country based caching useful?
This is especially useful if your website should provide different content for countries, such as legal disclaimers. KeyCDN country based caching allows you to deliver different versions of your content that comply with legal requirements, depending on which country your website visitor is located in.
Configure caching depending on the viewer's location
You can enable the Cache Key Country option in your Zone settings. The country code is derived from the client IP address. This will add the X-Country-Code
header to the origin request with the two-letter country code (ISO 3166-1 alpha-2).
Here is an example of what a request would look like. Suppose an image with the URL https://example-1.kxcdn.com/path/to/example.jpg
is viewed from the US:
GET /path/to/example.jpg HTTP/1.1
Host: your_origin_host
X-Forwarded-Host: example-1.kxcdn.com
X-Forwarded-For: 1.2.3.4
X-Forwarded-Scheme: http
X-Pull: KeyCDN
X-Country-Code: US
Connection: close
Accept: */*
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36
Accept-Language: en-US,en
There will be different variants in the cache for the same asset. Here an example list:
/path/to/example.jpgUS
/path/to/example.jpgDE
/path/to/example.jpgFR
...
Please find here a list of the country codes.
The following nginx snippet gives you an idea how to use this on your server:
location / {
if ($http_x_country_code ~* "US") {
rewrite ^(.*)$ /us/$1;
}
...
}
Keep in mind using this feature will decrease the cache hit ratio (CHR) as there are more variants in the cache on our edge servers.
The Cache Key Country option is a neat way to address country based caching policies without adding complex redirects in your backend. Country based caching can now be enabled in your KeyCDN Zone settings at no additional cost.