Skip to content

Commit a9bcb86

Browse files
authored
docs: update (#66)
1 parent 05455f6 commit a9bcb86

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,8 @@ sharedCache: {
658658
}
659659
```
660660

661+
**⚠️ Performance Warning**: By default, SharedCache processes Vary headers which requires **two KV storage queries** per cache lookup. If you're using a slow KV storage (like remote Redis), this can significantly impact performance. Consider setting `ignoreVary: true` to disable Vary processing and use only one query per lookup.
662+
661663
#### `cacheKeyRules`
662664

663665
Customize how cache keys are generated to optimize cache hit rates and handle different caching scenarios:
@@ -1241,7 +1243,7 @@ interface CacheQueryOptions {
12411243
**Unsupported Options (throw errors):**
12421244

12431245
- **`ignoreSearch`**: Query string handling not customizable
1244-
- **`ignoreVary`**: Vary header processing not bypassable
1246+
- **`ignoreVary`**: Vary header processing not bypassable (Note: This option is actually supported in SharedCache)
12451247

12461248
### 📊 Compliance Summary
12471249

@@ -1318,6 +1320,32 @@ When using SharedCache with meta-frameworks, you can develop with a consistent c
13181320
- **stale-while-revalidate**: Serves cached content immediately while updating in background, providing zero-latency responses
13191321
- **stale-if-error**: Serves cached content when origin servers fail, improving uptime and user experience
13201322

1323+
### Q: How does SharedCache handle Vary headers and what are the performance implications?
1324+
1325+
**A:** SharedCache processes Vary headers by default, which requires **two KV storage queries** per cache lookup:
1326+
1327+
1. First query: Get Vary metadata from base cache key
1328+
2. Second query: Get actual response from variant cache key
1329+
1330+
**Performance Impact:**
1331+
- **Local Redis**: Minimal impact (0.2-1ms additional latency)
1332+
- **Remote Redis**: Significant impact (4-20ms additional latency)
1333+
- **Database storage**: High impact (10-50ms additional latency)
1334+
1335+
**Recommendation for slow storage:**
1336+
```typescript
1337+
// Disable Vary processing for better performance
1338+
const fetch = createFetch(cache, {
1339+
sharedCache: {
1340+
ignoreVary: true, // Reduces to single query per lookup
1341+
},
1342+
});
1343+
```
1344+
1345+
**Trade-offs:**
1346+
- **With Vary**: RFC compliant, supports content negotiation, but slower
1347+
- **Without Vary**: Faster performance, but may serve incorrect content for requests with different headers
1348+
13211349
```typescript
13221350
// Best practice: Use both directives together
13231351
const fetch = createFetch(cache, {

0 commit comments

Comments
 (0)