HttpCacheClient class
A simple HTTP client with caching support.
Wraps the standard http client and provides in-memory caching for HTTP requests.
By default, GET and POST requests are cached, while PUT and DELETE requests are not.
Constructors
- HttpCacheClient({required String baseUrl, Duration cacheTimeout = const Duration(minutes: 5), KeyGenerator? keyGenerator, Client? httpClient})
- Creates a new HTTP client with caching support.
Properties
- baseUrl → String
-
The base URL for all HTTP requests.
final
- cacheTimeout → Duration
-
The duration for which cached responses remain valid.
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
-
clearCache(
) → void - Clears all cached responses.
-
delete(
String uri, {Map< String, String> ? headers, Map<String, String> ? queryParams}) → Future<Response> - Performs a DELETE request (not cached by default).
-
get(
String uri, {Map< String, String> ? headers, Map<String, String> ? queryParams, bool cacheResult = true}) → Future<Response> - Performs a GET request with optional caching.
-
handleRedirects(
Response response) → Future< Response> - Handles HTTP redirects for responses with 301 or 302 status codes.
-
invalidateCache(
{required String uri, required REQUEST_METHODS method, Object? body}) → void - Invalidates a specific cached response.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
post(
String uri, {Map< String, String> ? headers, Map<String, String> ? queryParams, Object? body, bool cacheResult = true}) → Future<Response> - Performs a POST request with optional caching.
-
put(
String uri, {Map< String, String> ? headers, Map<String, String> ? queryParams, Object? body}) → Future<Response> - Performs a PUT request (not cached by default).
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited