Cloud CDN is not separating PC and SP caches properly
Current Configuration
We are using Cloud CDN and trying to separate the cache for PC and SP (smartphone) users with the following configurations:
- Adding the
X-Device-Typeheader via Cloud Armor
User-Agentis checked, andX-Device-Type: pcis added for PC users, whileX-Device-Type: mobileis added for SP users.- Verified that this is applied correctly using:
gcloud compute security-policies describe pc-sp-separation-policy --format=json
- CakePHP 2 also retrieves the
X-Device-Typeheader and includes it in the response withVary: X-Device-Type.
- Adding
X-Device-Typeto the Cloud CDN cache key
gcloud compute backend-services update exsample
–global
–cache-key-include-http-header=“X-Device-Type”
- Confirmed that
X-Device-Typeis included in the cache key via:
gcloud compute backend-services describe exsample --global --format=json | jq ‘.cdnPolicy.cacheKeyPolicy’
- Confirming response headers
We verified that Cloud Armor successfully adds theX-Device-Typeheader by checking CakePHP 2 logs and response headers:
curl -I -H “User-Agent: Mozilla/5.0 (iPhone)” https://exsample.com/
Response:
HTTP/2 200
cache-control: public, max-age=30
vary: X-Device-Type
content-type: text/html; charset=UTF-8
x-device-type: mobile
Issue
Even after implementing the above settings, the cache is not being separated properly.
- When accessing from a PC, the response is cached.
- When accessing from an SP device afterward, the PC-cached response is returned (instead of a separate cache for SP).
- The Cloud CDN log (
cacheDecision) does not showINCLUDE_HTTP_HEADER, which might indicate thatX-Device-Typeis not included in the cache key.
Question
Is there anything missing in the configuration to ensure Cloud CDN properly separates caches for PC and SP?