NetworkSanitizerInterceptor class
A Dio interceptor that provides HTTP request caching and deduplication.
This interceptor automatically caches HTTP responses and prevents duplicate simultaneous requests. It supports configurable cache duration and allows for custom cache storage implementations.
Features
- Request Caching: Stores responses based on request parameters
- Request Deduplication: Prevents duplicate simultaneous requests
- Cache Invalidation: Supports force refresh functionality
- Configurable Duration: Set custom cache expiration times
- Custom Storage: Use your own cache storage implementation
Usage
final dio = Dio();
dio.interceptors.add(
NetworkSanitizerInterceptor(const Duration(minutes: 5)),
);
Force Refresh
final response = await dio.get(
'/api/users',
options: Options(extra: {'invalidateCache': true}),
);
Constructors
- NetworkSanitizerInterceptor(Duration _cacheDuration)
- Creates a NetworkSanitizerInterceptor with the specified cache duration.
- NetworkSanitizerInterceptor.custom({required Duration cacheDuration, required SanitizerCacheManager cacheManager})
- Creates a NetworkSanitizerInterceptor with a custom cache manager.
Properties
- 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 - Handles request errors by notifying all waiting duplicate requests.
-
onRequest(
RequestOptions options, RequestInterceptorHandler handler) → void - Handles incoming requests by checking cache and deduplicating requests.
-
onResponse(
Response response, ResponseInterceptorHandler handler) → void - Handles successful responses by caching them and resolving duplicate requests.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited