Which properties of a request will be considered as parts of a key

When I use Cache API, and call cache.match or cache.put, the first parameter is a Request Object. I wonder except for request.url, which other properties will be used to determine if it’s the same key.
Thank you all!

@200706991 are you able to figure it out? I’m looking for the same

Here’s Cloudflare’s default cache key.


You can construct other cache keys with workers, so if you have, the cache key would be based on whatever it is you decided to base it on.

Does the cache key include “user-agent” or anything similar from the browser? I’m seeing a similar issue here: Different Cache 'Age' for same file, from different browsers/incognito @cscharff

No. And adding user-agent to the cache key is a bad idea. It currently contains too much variation to be a useful cache key (is Chrome so different from Chrome that it needs a different cache?). In the future it will probably not contain enough information to be a useful cache key (as browsers are moving towards a situation where the UA is a static string forever)

The default cache-key is:

  • Protocol (Towards the Origin, http or https)
  • Hostname (www.example.com)
  • URL Path (/something/image.jpg)
  • URL Query String (?v=2.1&foo=bar)
  • Origin HTTP Request Header. (https://www.example.net)

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.