-
-
Notifications
You must be signed in to change notification settings - Fork 675
feat: add request deduplication to cache interceptor #4679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Implements request deduplication for the cache interceptor to prevent multiple identical concurrent requests from being sent to the origin server. When multiple requests for the same resource are made while one is already in-flight, subsequent requests wait for the original request to complete and share its response. This optimization reduces unnecessary network traffic and server load when handling concurrent identical requests, particularly useful in scenarios where the same resource is requested multiple times before the cache is populated. Changes: - Add CacheDeduplicationHandler to manage multiple waiting handlers - Add makeDeduplicationKey utility for generating request keys - Integrate deduplication logic into cache interceptor - Add comprehensive tests for deduplication scenarios Signed-off-by: Matteo Collina <[email protected]>
- Add 'undici:cache:pending-requests' diagnostic channel - Publish events when pending requests are added/removed - Add tests for error cleanup and map state verification - Replace callback approach with Node.js diagnostics channel 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Matteo Collina <[email protected]>
- Document request deduplication feature in cache interceptor section - Add undici:cache:pending-requests diagnostic channel documentation - Include examples for monitoring deduplication behavior 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Matteo Collina <[email protected]>
|
I had claude opus 4.5 prepare this. Looks good enough but a second opionion would be interesting. I opted to not put the dedupe burden on the cache storage. This means that in a distributed cache scenario, you’ll |
Creating the deduplication cache key is relatively expensive, so this feature is now disabled by default and can be enabled with the `deduplication: true` option. - Add `deduplication` option to cache interceptor (default: false) - Update TypeScript types with new option - Update documentation to reflect opt-in behavior - Update all tests to explicitly enable deduplication 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Matteo Collina <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4679 +/- ##
==========================================
+ Coverage 92.86% 92.87% +0.01%
==========================================
Files 107 108 +1
Lines 33499 33791 +292
==========================================
+ Hits 31108 31385 +277
- Misses 2391 2406 +15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Adds request deduplication to the cache interceptor. When enabled via the
deduplication: trueoption, concurrent identical requests are deduplicated so only one request is sent to the origin server, and all waiting handlers receive the same response.This feature is opt-in because creating the deduplication cache key has some overhead.
Changes
lib/handler/cache-deduplication-handler.js- Handler that buffers responses for multiple waiting handlerstest/interceptors/cache-deduplication.js- Comprehensive test suite (14 tests)lib/util/cache.js- AddedmakeDeduplicationKey()functionlib/interceptor/cache.js- Added deduplication logic with pending requests maptypes/cache-interceptor.d.ts- Addeddeduplicationoption typedocs/docs/api/Dispatcher.md- Documented the feature and optiondocs/docs/api/DiagnosticsChannel.md- Documentedundici:cache:pending-requestschannelUsage
Observability
A diagnostic channel
undici:cache:pending-requestsis available for monitoring:Test plan
🤖 Generated with Claude Code