On this page
article
Deduplicate
Deduplicate ensures that only one execution is in flight for a given key at a time. If the same key is requested while a previous call is still pending, the new caller receives the same future.
Deduplicate
What it is
Deduplicate ensures that only one execution is in flight for a given key at a time. If the same key is requested while a previous call is still pending, the new caller receives the same future.
When to use it
- Preventing thundering herd on cache misses.
- Coalescing identical network requests.
- Avoiding duplicate expensive computations started in parallel.
Async / sync support
| Wrapper | Support |
|---|---|
Func<R> | ✅ Async |
Func1<T, R> | ✅ Async |
Func2<T1, T2, R> | ✅ Async |
FuncSync<R> | ❌ No |
API reference
| |
No parameters.
Examples
Basic example
| |
Real-world example
| |
Best practices
- Use
deduplicatefor idempotent reads. - Combine with
memoizeif you want to remember the result after completion, not just coalesce in-flight calls. - Be careful with functions whose result depends on time or side effects.
Common pitfalls
- Side effects run once: If the function has side effects, deduplication means they happen only once even if called many times.
- No result caching after completion: After the future completes, a new call starts a new execution.