The type of values to cache/track
Creates a new SingleFlight instance.
The type of values to cache/track
Optionalopts: SingleFlightOptions<T>Configuration options
Clear all state (cache + in-flight).
Clear only cache entries.
Get cached value if exists and not expired.
Returns null if not cached or expired.
Returns { isStale: true } if past staleAt but before expiresAt.
Cache key
Cache entry or null if not found/expired
Get in-flight entry if exists.
Request key
In-flight entry or null if not in-flight
Check if key is cached (without returning value).
Note: May return true for expired items if adapter doesn't clean eagerly.
Cache key
true if key exists in cache
Check if key has in-flight request.
Request key
true if request is in-flight
Invalidate cache entries matching a predicate.
Uses adapter's keys() method if available (MapCacheAdapter has it).
Returns 0 if adapter doesn't support key iteration.
Function that returns true for keys to delete
Number of entries deleted
Join an existing in-flight request.
Increments waitingCount and returns new count.
Request key
New waiting count, or 0 if no in-flight request
Set a cache entry.
Cache key
Value to cache
Optionalopts: SetCacheOptionsOptional TTL and staleIn overrides
A generic coordinator for cache and in-flight request deduplication.
SingleFlight is a state manager that provides primitives for:
It does NOT handle execution - callers control the flow and use SingleFlight as a coordination layer.
Core principles:
Example
Example