You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`withCredentials`| Whether credentials (cookies) are included in the request. ||
1345
1345
1346
-
These properties are combined and hashed to create a unique cache key for each request. This ensures that requests with different parameters, bodies, or headers are cached separately.
1346
+
#### Header Filtering for Cache Keys
1347
+
1348
+
To ensure stable cache keys and prevent unnecessary cache misses, `fetchff` only includes headers that affect response content in cache key generation. The following headers are included:
1349
+
1350
+
**Content Negotiation:**
1351
+
1352
+
-`accept` - Affects response format (JSON, HTML, etc.)
1353
+
-`accept-language` - Affects localization of response
1354
+
-`accept-encoding` - Affects response compression
1355
+
1356
+
**Authentication & Authorization:**
1357
+
1358
+
-`authorization` - Affects access to protected resources
1359
+
-`x-api-key` - Token-based access control
1360
+
-`cookie` - Session-based authentication
1361
+
1362
+
**Request Context:**
1363
+
1364
+
-`content-type` - Affects how request body is interpreted
1365
+
-`origin` - Relevant for CORS or tenant-specific APIs
1366
+
-`referer` - May influence API behavior
1367
+
-`user-agent` - Only if server returns client-specific content
Headers like `user-agent`, `accept-encoding`, `connection`, `cache-control`, tracking IDs, and proxy-related headers are **excluded** from cache key generation as they don't affect the actual response content.
1383
+
1384
+
These properties are combined and hashed to create a unique cache key for each request. This ensures that requests with different parameters, bodies, or cache-relevant headers are cached separately while maintaining stable cache keys across requests that only differ in non-essential headers. If that does not suffice, you can always use `cacheKey` (string | function) and supply it to particular requests. You can also build your own `cacheKey` function and simply update defaults to reflect it in all requests. Auto key generation would be entirely skipped in such scenarios.
0 commit comments