RequestDeduplicationInterceptor class
A Dio interceptor that deduplicates identical concurrent requests.
When multiple identical requests are made simultaneously (e.g., due to rapid UI rebuilds or multiple widgets requesting the same data), only the first request is actually sent to the server. Subsequent identical requests wait for the first one to complete and receive the same response.
This optimization:
- Reduces unnecessary network traffic
- Prevents redundant server load
- Improves app performance by avoiding duplicate work
Requests are considered identical if they have the same:
- HTTP method
- Path
- Query parameters
- Authorization header
By default, only GET and HEAD requests are deduplicated since they are safe and idempotent. POST, PUT, DELETE, and PATCH requests are not deduplicated as they may have side effects.
Example:
dio.interceptors.add(RequestDeduplicationInterceptor());
// These two concurrent calls will only result in one network request
final future1 = client.get('/users/123');
final future2 = client.get('/users/123');
// Both futures receive the same response
final results = await Future.wait([future1, future2]);
- Inheritance
-
- Object
- Interceptor
- RequestDeduplicationInterceptor
Constructors
-
RequestDeduplicationInterceptor({bool enabled = true, List<
String> deduplicateMethods = const ['GET', 'HEAD']}) - Creates a new RequestDeduplicationInterceptor.
Properties
-
deduplicateMethods
→ List<
String> -
HTTP methods that should be deduplicated.
final
- enabled → bool
-
Whether deduplication is enabled (default: true).
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onError(
DioException err, ErrorInterceptorHandler handler) → void -
Propagates errors to waiting requests when the original request fails.
override
-
onRequest(
RequestOptions options, RequestInterceptorHandler handler) → void -
Intercepts outgoing requests and deduplicates them if applicable.
override
-
onResponse(
Response response, ResponseInterceptorHandler handler) → void -
Completes waiting requests when the original request succeeds.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited